godius Posted October 5, 2009 Share Posted October 5, 2009 Hey guys, i have a javascript function which fetches data from a PHP file, then posts it back to a DIV. This works great, in all browsers. But now I wanted to get data into the DIV in realtime, so it doesnt have to wait for the PHP script to complete all its data, for this I use ReadyState == 3 instead of ReadyState == 4. Now this works great in Firefox, but in IE 8 and Google Chrome it does not want to work. function ajaxDo(user_key,option_id) { var req = null; var user_key = user_key; var option_id = option_id; var link = "/ajax_tools.php?uri=" + user_key + "&o=" + option_id; document.getElementById("tools_output").style.display="block"; document.getElementById("tools_output").innerHTML="Loading data..."; document.getElementById("tools_output_status").style.display="block"; if(window.XMLHttpRequest) req = new XMLHttpRequest(); else if (window.ActiveXObject) req = new ActiveXObject("Msxml2.XMLHTTP"); req.onreadystatechange = function() { if(req.readyState == 3) { document.getElementById("tools_output").innerHTML=req.responseText; } if(req.readyState == 4) { document.getElementById("tools_output_status").style.display="none"; } }; req.open("POST", link, true); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.send(null); } This is the whole function posted above, the part that is playing up is if(req.readyState == 3) { document.getElementById("tools_output").innerHTML=req.responseText; } Its seem Chrome and IE8 do not know readyState == 3, only 4. What can I do about this? Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 6, 2009 Share Posted October 6, 2009 Hi Had a brief play using the following and Chrome did pop up with a state change to 3. This is using the zxml.js library for the Ajax call. <html> <head> <script type="text/javascript" src="Includes/zxml.js"></script> <script> function ajaxDo() { if (zXmlHttp.isSupported()) { var oXHR = zXmlHttp.createRequest(); var QueryString = "baseplay.php"; oXHR.open("get",QueryString, true); oXHR.onreadystatechange = function () { alert(oXHR.readyState); }; } oXHR.send(null); } </script> </head> <body onLoad='ajaxDo()'> </body> </html> All the best Keith Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.