ryancey
ryancey

Reputation: 1057

How to access an object returned by jQuery.post()?

I am storing AJAX requests for further treatment in an array, with requests.push($.post('/validate', postData)); within a .each() loop.

When I dump these objects, the Chrome web inspector show this:

Object {readyState: 1, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}

And so on, for each objects of the array. In these objects, I want to get the responseText (the data returned by the AJAX query). I can't figure out how to do it.

request.responseText doesn't seem to work.

Upvotes: 1

Views: 67

Answers (2)

royse41
royse41

Reputation: 2368

You're logging the ajax request, not the ajax response.

You'll need a success method, which will allow you to get to the response returned from the server.

Directly from the documentation:

$.post( "ajax/test.html", function( data ) {
  $( ".result" ).html( data );
});

Upvotes: 1

Rohan Kumar
Rohan Kumar

Reputation: 40639

Try it like,

$.post('/validate', postData,function(data){
    requests.push(data); // push response in array here
});

Upvotes: 0

Related Questions