Processing responses on JQuery Ajax requests to return them

I’m in a bit of a problem, I have a function that sends an ajax request.
I have seen the other questions regarding this topic, but it seems that the answers doesn’t solve my problem.

function callXHR(params)
{
    var req = $.post(params.url, params.data);   

    // process for success
    req.success(function(response){

       // response processing
    });


    // this function needs to return the processed response from
    // my req.success
    return; //<the value processed on the req.success>;

}

I have already studied the concept of deferred objects and promises. The thing is i just don’t know how to wait for the ajax call to be resolve before i return the values and end my function.

thank you very much!

cheers!!!


Source: jquery

Leave a Reply