0

I'm trying to load my b.html in the same folder as my main html but it won't load. I've copied the whole example from W3School and it doesn't do anything when I tes it manually by clicking my HTML file in my folder.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("#div1").load("b.html");
    });
});
</script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>
</body>
</html>
Steve Ruru
  • 143
  • 1
  • 3
  • 11
  • 1
    If the `b.html` file is in the same folder as the current page this should work fine. Check the console for errors after making the AJAX request from the `load()` function. Also, please don't use W3Schools as a reference. Their articles are often outdated and sometimes just plain wrong. The jQuery documentation is far more comprehensive and accurate in this case: http://api.jquery.com/load – Rory McCrossan Jun 21 '18 at 07:48
  • 2
    Also - make sure you're not running on your local file system, ie. `file://C:/folder/yourpage.html`. You cannot make AJAX requests under this protocol for obvious security reasons. You need to run on a webserver. You can easily install XAMP or IIS. – Rory McCrossan Jun 21 '18 at 07:49
  • Thank you, I didn't use XAMPP before. Now it works. Got it now ^^ – Steve Ruru Jun 21 '18 at 07:52

0 Answers0