js_280 Posted August 19, 2007 Share Posted August 19, 2007 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 https://forums.phpfreaks.com/topic/65719-solved-readystate-hangs-at-readystate-3/ Share on other sites More sharing options...
js_280 Posted August 19, 2007 Author Share Posted August 19, 2007 Nevermind... Figured it out as soon as I posted... I forgot to clear the innerHTML on the div before I appended the data... Link to comment https://forums.phpfreaks.com/topic/65719-solved-readystate-hangs-at-readystate-3/#findComment-328273 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.