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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.