I wrote an Ajax function as shown below.
It does not work properly. If I remove xmlhttp.status==400 then it will work. What mistake did I make in this example?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <script type="text/javascript"> function getAjax() { if (window.XMLHTTPRequest) { xmlhttp=new XMLHTTPRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.xmlHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==400) { document.getElementById('mydiv').innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","testajax.txt",true); xmlhttp.send(null); } </script> </head> <body> <input type="button" value="Get content" onclick="getAjax()"><br> <div id="mydiv"></div> </body> </html>
source share