Function Not Returning Value - Programmers Heaven

Howdy, Stranger!

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


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Function Not Returning Value

DRockDRock Posts: 1Member
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')));


if (response.substring(0,4) == "FAIL")
} [/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();, url, true);
request.onreadystatechange = function() {
if (request.readyState == 4)
if (request.status == 200)
return request.responseText;
return "FAIL" + request.status;
if (method == "POST")
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
} [/code]

Like I said, I don't think this is a problem with createRequest since I use it everywhere else on my site ( 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.