[英]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));
我正在使用requests.push($.post('/validate', postData));
在数组中存储AJAX请求以进行进一步处理requests.push($.post('/validate', postData));
within a .each()
loop. 在.each()
循环中。
When I dump these objects, the Chrome web inspector show this: 当我转储这些对象时,Chrome Web检查器将显示以下内容:
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). 在这些对象中,我想获取responseText
(AJAX查询返回的数据)。 I can't figure out how to do it. 我不知道该怎么做。
request.responseText
doesn't seem to work. request.responseText
似乎不起作用。
You're logging the ajax request, not the ajax response. 您正在记录ajax请求,而不是ajax响应。
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
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.