jquery - Unable to load a text through a local host -
question: why error suggests "different-origin" material, , how fix it? i'm trying recreate this simple example (click on "try yourself") on machine using python's simplehttpserver. i've created demo_test.txt (with same contents example). demo_test.txt , jquery-2.1.4.min.js both in root directory server started. code runs fine until tries access demo_test.txt, @ point gives error:
xmlhttprequest cannot load file:///users/username/project/demo_test.txt. cross origin requests supported protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
if instead try load them urls (commented out lines) different error:
no 'access-control-allow-origin' header present on requested resource.
i understand bit same-origin policy, must somehow violating it. can me out?
<!doctype html> <html> <head> <script src="jquery-2.1.4.min.js"></script> <!-- <script src="http://127.0.0.1:8000/jquery-2.1.4.min.js"></script> --> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").load("demo_test.txt"); // $("#div1").load("http://127.0.0.1:8000/demo_test.txt"); }); }); </script> </head> <body> <div id="div1"><h2>let jquery ajax change text</h2></div> <button>get external content</button> </body> </html>
Comments
Post a Comment