Chikwado Posted August 21, 2015 Share Posted August 21, 2015 Can some one help explain what am doing wrong here. Ajax Code Ajax Page I have a text file ajax.txt, Some one help check it. Link to comment Share on other sites More sharing options...
alexnofue Posted August 21, 2015 Share Posted August 21, 2015 Hello, the xmlhttp.onreadystatechange=function() {} line is an anonymous function assigned to xmlhttp.onreadystatechange, that means that it should have an semicolon to end the expression, or a new line. <!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("divpage").innerHTML = xmlhttp.responseText; } }; xmlhttp.open("GET","ajax.txt",true); xmlhttp.send();}</script></head><body><div id="divpage"></div><button onclick="loadXMLDoc()">Get ajax</button></body></html> Link to comment Share on other sites More sharing options...
Ingolme Posted August 21, 2015 Share Posted August 21, 2015 The error console says "loadXMLDoc() is not defined". Since all your code is on one line, you need to be extra careful to end everything with a semi-colon. 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