[jQuery] How to return data when calling an ajax function?

[jQuery] How to return data when calling an ajax function?


Hi, if I have the following code:
function xhr(sWT){
    var dReturn;
    $.ajax({
        type: "GET",
        url: sWT,
        error: function(errorData){
            dReturn = errorData;
        },
        success: function(successData){
            dReturn = successData;
        },
        complete: function(){
            return dReturn;
        }
    });
}
xhr('http://foo.com');
...how can I call the xhr(); function so that it returns the response
from the ajax call? At the moment it's not working - I'm guessing
that's because I'm still inside the $.ajax jQuery object when I
"return dReturn".
If I put "return dReturn" outside of the $.ajax function, it returns
the dReturn before the ajax call has completed (and thereby giving me
an error of dReturn is undefined);