我正在尝试计算我的 $.ajax 调用中的结果数。
$.ajax({
'async': true,
'crossDomain': true,
'url': 'XXX',
'method': 'GET',
'headers': {
'key': 'XXX',
'scope': 'XXX',
'content-type': 'application/json',
'cache-control': 'no-cache'
},
'processData': false,
'data': {},
error: function(jqXHR, textStatus, errorThrown) {
// Default error
log('error');
},
success: function(data, textStatus, jqXHR) {
log('success');
log(data);
var ArrayContent = data.length;
log(ArrayContent)
}
}).done(function(response) {
log('done');
});
我的 jSon 响应是 Object {3858: Object, 4667: Object, 4668: Object, 4680: Object, 4710: Object}3858: Object4667: Object4668: Object4680: Object4710: Object__proto__: Object
我已经尝试了在此站点上找到的几种解决方案,但我无法使它们中的任何一种起作用。
对于解决方案的任何建议将不胜感激。
-C
最佳答案
您可以使用以下代码找到对象中自己的可枚举属性的数量:
Object.keys(response).length;
关于jquery - 如何计算 jQuery $.ajax 结果中的响应数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36648714/