0

I got this example code from W3schools.com and want to use it on my website but it has failed to work in chrome and opera, it's only working in firefox. Please what went wrong.

<!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("demo_test.txt");
});
});
</script>
 </head>
<body>

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

<button>Get External Content</button>

</body>
</html>
Stephen
  • 11
  • 5

1 Answers1

1

You have opened your HTML-File from filesystem?

In this case I got this error:

Failed to load file:///path/to/test.html: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

It means chrome doesnt allow this request for security reasons.

So you need a webserver to use http protocol or disable this security.

Disable same origin policy in Chrome

Anyway its a good idea using console to see errors.

https://developers.google.com/web/tools/chrome-devtools/shortcuts

search for "Open the Console panel"

m ba
  • 124
  • 4