Jump to content

[SOLVED] readyState hangs at readyState 3


js_280

Recommended Posts

Only a month using AJAX and less than 3 days using JSON, so this is probably a stupid mistake...

 

Here's the client side...

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>JSON Client</title>
<script type="text/javascript" language="javascript">
var request = null;

try
{
	request = new XMLHttpRequest();
}
catch(e)
{
	try
		{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch(e2)
		{
			try
				{
					request = new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(e3)
				{
					alert("Your browser is not AJAX compatible!");
				}
		}
}

function sendRequest()
{
var url = './json_server.php';
request.open("GET", url, true);
request.onreadystatechange = doResponse;
request.send(null);
}

function doResponse()
{
if(request.readyState == 4)
{
	if(request.status == 200)
	{
		var response = eval('(' + request.responseText + ')');

		for(var i = 0; i <= response.car.length - 1; i++)
		{
			document.getElementById('data_div').innerHTML += response.car[i] + '<br />';
		}
	}
	else
	{
		document.getElementById('data_div').innerHTML = '<div align="center"><h3>Error Loading Data...</h3></div>';
	}
}
else
{
	document.getElementById('data_div').innerHTML = '<div align="center"><img src="./images/loader.gif" title="Loading..." alt="Loading..." /></div>';
}
}
</script>
</head>

<body>
<div align="center">
<div id="data_div" style="height: 400px; width: 400px; background-color: #cccccc; border: 1px solid #000000; font-size: 38px; color: #000000; font-weight: bold;">
</div>
<br />
<br />
<input type="button" value="Run JSON Test" onclick="sendRequest();" />
</div>
</body>
</html>

 

Here's the server side...

 

<?php
header("Content-type: text/plain");
$data = '{ "car" : ["color", "red"] }';
echo($data);
exit;
?>

 

When I check the readyState it stays 3 and never returns a readyState of 4, so the loader animation never ends even though it returns the data...

 

What am I doing wrong?  It works if I don't have the "For" loop and simply return response.car[0]

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.