Jump to content

ReadyState == 3 Problem With IE and Chrome


godius

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/176553-readystate-3-problem-with-ie-and-chrome/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.