遍历JSON响应失败 [英] Loop through JSON response fails
本文介绍了遍历JSON响应失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从服务器获取JSON响应:
I get JSON response from a server:
[{"id":605,"vote":1},{"id":606,"vote":-1},{"id":611,"vote":1},{"id":609,"vote":-1}]
然后我尝试遍历结果并获取对象属性:
Then I try to loop through results and get objects properties:
success:
function (data) {
$.each(data, function() {
$.each(this, function(i, v) {
alert(i+v);
});
});
}
但是我的代码以某种方式失败,并且没有显示警报.我在做错人吗?
But somehow my code fails and no alert is shown. What am I doing wrong guys?
推荐答案
在ajax请求中将dataType
指定为"json"
:
Specify dataType
to "json"
in your ajax request:
$.ajax({
//...
dataType:"json",
success://etc...
这篇关于遍历JSON响应失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文