Matej Posted July 8, 2014 Share Posted July 8, 2014 (edited) Hi , im trying to understand ajax , here is my script <!DOCTYPE html><html><head><script>function loadXMLDoc(){var xmlhttp;if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } }xmlhttp.open("get","texttest.txt",true);xmlhttp.send();}</script></head><body> <div id="myDiv"><h2>Let AJAX change this text</h2></div><button type="button" onclick="loadXMLDoc()">Change Content</button> </body></html> the texttest.txt contains just <p>hello world</p> but it isnt working , it writes Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file can anyone help me please? Edited July 8, 2014 by Matej Link to comment Share on other sites More sharing options...
justsomeguy Posted July 8, 2014 Share Posted July 8, 2014 How are you testing it? Are you uploading to a web server or just double-clicking on the file? It will probably work on a server, but your browser uses different permissions if you open a local file. Link to comment Share on other sites More sharing options...
Matej Posted July 8, 2014 Author Share Posted July 8, 2014 im opening(double clicking) on .html file Link to comment Share on other sites More sharing options...
justsomeguy Posted July 8, 2014 Share Posted July 8, 2014 Then that's probably why the browser won't load the file. Link to comment Share on other sites More sharing options...
thescientist Posted July 9, 2014 Share Posted July 9, 2014 in other words, you need to execute this within the context of a running web server. You can either set that up locally using an AMP stack targetted for your OS (WAMP - Windows, LAMP - Linux, MAMP - OSX) or get hosting (free, shared, etc) and test by uploading your files there. Locally developing will greatly increase your productivity and reduce development cycles, so it's definitely recommended and preferred to have a functioning local development environment. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now