jquery - Load data from text file with ajax/javascript into html problems -
i want load data text file in same folder html file on computer won't work. in process of learning ajax , put little test myself test.html , text file test.txt. advice please, appreciated.
<!doctype html> <html> <head> <title>test</title> <script> function loaddata() { var test; test=new xmlhttprequest(); test.onreadystatechange=function() { if (test.readystate==4 && test.status==200) { document.getelementbyid("test").innerhtml=test.responsetext; } } test.open("get","test.txt",true); test.send(); } </script> </head> <body> <div id="test"></div> <button type="button" onclick="loaddata()">get data</button> </body> </html>
when press button, nothing happens. on site saw similar example data text file displayed above button.
the problem you're accessing files directly on local system; web browsers have been designed not allow in order prevent saved web pages loading personal files disks , uploading them remote servers. in order make work, you'll need run web server locally , use view files. recommend apache web server, flexible , can used on windows, linux or osx.
Comments
Post a Comment