Javascript AJAX function returns undefined instead of true / false

Posted by Josh K on Stack Overflow See other posts from Stack Overflow or by Josh K
Published on 2010-05-11T19:51:37Z Indexed on 2010/05/11 19:54 UTC
Read the original article Hit count: 300

I have a function that issues an AJAX call (via jQuery). In the complete section I have a function that says:

complete: function(XMLHttpRequest, textStatus)
{
    if(textStatus == "success")
    {
        return(true);
    }
    else
    {
        return(false);
    }
}

However, if I call this like so:

if(callajax())
{
    //  Do something
}
else
{
    // Something else
}

The first is never called.

If I put an alert(textStatus) in the complete function I get true, but not before that function returns undefined.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery