0

I found this example on w3schools.com and it should be working(it works on the website) but it doesn't work when I write it on my IDE(Atom).the home page is looking good but when I clicking the button nothing happened and it's not loading the demo_test.txt file. what am I doing wrong? or maybe something is missing?

home.html

$(document).ready(function(){
  $("button").click(function(){
    $("#div1").load("demo_test.txt");
  });
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>

<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>

<button>Get External Content</button>

</body>
</html>

demo_test.txt

jQuery and AJAX is FUN!!!

This is some text in a paragraph.


11
  • Something in the console? Commented Oct 24, 2019 at 14:19
  • Try to put <script> tag right before </body> . Commented Oct 24, 2019 at 14:21
  • @Aaron3219 I don't know. I don't have any alerts on the console. but the browser doesn't load the second file Commented Oct 24, 2019 at 14:23
  • @AhmedTagAmer I tried. still doesn't work Commented Oct 24, 2019 at 14:24
  • Is the file demo_test.txt on the same folder level as home.html? Commented Oct 24, 2019 at 14:27

1 Answer 1

1

To start use Ajax, you must host your website or application on your machine, this called localhost.

There is many FREE applications you can use to create a localhost:

Download any of applications above and install it, it's very easy.

After installation, you can access your website with link http://localhost or http://127.0.0.1 .

You can create localhost without using any applications with IIS (Internet Information Services), but it's complicated compared to above applications.

Sign up to request clarification or add additional context in comments.

1 Comment

If this answer solved you problem, please accept it as correct answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.