Netanel Ben Isahar
Netanel Ben Isahar

Reputation: 23

my HTML file cant load another file using load function(jquery)

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.


Upvotes: 0

Views: 35

Answers (1)

Ahmed Tag Amer
Ahmed Tag Amer

Reputation: 1422

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.

Upvotes: 1

Related Questions