...

View Full Version : Never reach readystate 4



ilbo
07-19-2009, 05:04 PM
Hello, for some reason I never reach readystate "4" for when I make a call to the search function below. It doesn't seem to matter if I make the call one or more times, but when I change "true" to "false" in the httpObject.open method, I reach readysate 4. The "method" variable specifies the file name (e.g. "helloworld.php"). Any thoughts?


function search(method){
var httpObject = getHTTPObject();
if (httpObject != null)
{
httpObject.open("GET", method, true);
httpObject.send(null);
httpObject.onreadystatechange = setOutput(httpObject);
}
}

function getHTTPObject(){
if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) return new XMLHttpRequest();
else
{
alert("Your browser does not support AJAX.");
return null;
}
}

function setOutput(httpObject){
if(httpObject.readyState == 4)
{
alert("Hello world!");
}
}

ckeyrouz
07-19-2009, 05:44 PM
Go to this URL:
http://www.devguru.com/Technologies/xmldom/quickref/obj_parseError.html


you might need to alert(httpObject.parseError.reason)

there are many xml debugging properties that you can find in this page.

randomuser773
07-19-2009, 10:15 PM
Hello, for some reason I never reach readystate "4" for when I make a call to the search function below. It doesn't seem to matter if I make the call one or more times, but when I change "true" to "false" in the httpObject.open method, I reach readysate 4. The "method" variable specifies the file name (e.g. "helloworld.php"). Any thoughts?

Perhaps:

httpObject.onreadystatechange = function(){ setOutput( this ); };

ilbo
07-19-2009, 11:13 PM
I'm not outputting any XML though. It's just a PHP script that performs several databasing operations.

ilbo
07-19-2009, 11:14 PM
Also, I'm positive that the setOutput function is being called. I just never get the "4" readystate value.

randomuser773
07-19-2009, 11:55 PM
Also, I'm positive that the setOutput function is being called. I just never get the "4" readystate value.Another thing I just noticed is that you must always install the readystatechange handler before calling send.

ilbo
07-20-2009, 12:01 AM
I moved the readystatechange handler up, but that doesn't seem to do it.

This is weird because I get the readystate 4 value when I use "false" in the httpObject.open method.

randomuser773
07-20-2009, 12:15 AM
I moved the readystatechange handler up, but that doesn't seem to do it.

This is weird because I get the readystate 4 value when I use "false" in the httpObject.open method.Another thing I just noticed is that the request object isn't global so it gets hosed when the creating function ends. That's why it survives for a synchronous request.
Looks like you made all the common mistakes in one attempt.

ilbo
07-20-2009, 01:40 AM
I made it global. No go. :confused:

randomuser773
07-20-2009, 02:03 AM
I made it global. No go. :confused:Perhaps you could show the updated code, or preferably a test URL?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum