Function Not Returning Value

This may be more appropriate in the Ajax forum, but I don't think it's actually a problem with my Ajax implementation. I have trying to make my Ajax implementation a little more streamlined by creating a function to send an Ajax request. I have had no problems with Ajax requests before I tried doing this. Below is the code I am using that calls my sendRequest function:

[code]function miles()
{
var response = sendRequest("miles.php", "POST", "name="+escape(getCookie('User')));

//alert(response);

if (response.substring(0,4) == "FAIL")
alert("TEST");
else
showMiles(response);
} [/code]

The script generates an error because response is not defined. Here is the sendRequest function:

[code]function sendRequest(url, method, parameters)
{
var request = createRequest();
request.open(method, url, true);
request.onreadystatechange = function() {
if (request.readyState == 4)
{
if (request.status == 200)
return request.responseText;
else
return "FAIL" + request.status;
}
};
if (method == "POST")
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send(parameters);
} [/code]

Like I said, I don't think this is a problem with createRequest since I use it everywhere else on my site (www.ymsrunning.com) without any problems. I have used Firebug to step through it and the responseText exists when I get to the function return. I have been pulling my hair out on this one (and I don't have much to spare) and would really appreciate if someone could help me with this. Thanks.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories