简体   繁体   中英

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.

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 );
});

Try it like,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM