MikoLone
05-08-2006, 10:52 PM
Here is a question that I have that you all may have an answer but I just can't figure it out. I have just worked around it but I am finally tired of that and want to see if there is a real answer out there.
Here it is.
I have a function that calls a function that sends an AJAX request to the server. When the response comes back, I want it returned to the original function so that I can handle the response.
Here is some sudo codish stuff
function soSomething(){
//do stuff
response = doAJAXCall();
alert(response);//alerts "UNDEFINED"
}
function doAJAXCall(){
req = getXMLHTTPRequest();//makes the proper http request
req.onreadystatechange = function () {
if (req.readyState == 4 ) {
returnXML = req.responseXML;
return returnXML;
}
}
req.open("POST", 'some.php.file', true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(null);
}
the alert(response) line gives me an undefined. But if I alert returnXML instead of the return returnXML in the doAJAXCall function then I get a xml object.
I always seem to be wanting to call an AJAX call and get the response but I can't do it. I have hacked through this by calling the same function that called the ajax function when the response comes in but that seems sloppy.
I thought it was a problem with the line req.open("POST", 'some.php', true); so I changed it to req.open("POST", 'some.php', false); and it worked exactly the same.
I am using firefox (I haven't tested in IE yet) and I am not sure if that makes a difference.
Thank you in advance for any suggestions that you may have.
Here it is.
I have a function that calls a function that sends an AJAX request to the server. When the response comes back, I want it returned to the original function so that I can handle the response.
Here is some sudo codish stuff
function soSomething(){
//do stuff
response = doAJAXCall();
alert(response);//alerts "UNDEFINED"
}
function doAJAXCall(){
req = getXMLHTTPRequest();//makes the proper http request
req.onreadystatechange = function () {
if (req.readyState == 4 ) {
returnXML = req.responseXML;
return returnXML;
}
}
req.open("POST", 'some.php.file', true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(null);
}
the alert(response) line gives me an undefined. But if I alert returnXML instead of the return returnXML in the doAJAXCall function then I get a xml object.
I always seem to be wanting to call an AJAX call and get the response but I can't do it. I have hacked through this by calling the same function that called the ajax function when the response comes in but that seems sloppy.
I thought it was a problem with the line req.open("POST", 'some.php', true); so I changed it to req.open("POST", 'some.php', false); and it worked exactly the same.
I am using firefox (I haven't tested in IE yet) and I am not sure if that makes a difference.
Thank you in advance for any suggestions that you may have.