对不起n00b
我有一个简单的 json jquery 调用,但遇到问题。
<script>
$(document).ready(function(){
var table = $('#datatable');
$.ajax({
type: 'GET',
url: 'http://jsonurl',
dataType: 'jsonp',
success: function(data) {
$.each(data.responseData.leaderboard, function(i, item){
var rowItem = '<tr><td>' + item.userid +
'</td><td>' + item.username +
'</td><td>' + item.companyname +
'</td/></tr>';
table.append(rowItem);
return i<4;
});
}
});
});
</script>
json url 返回这样的结果
{"status": "success",
"message": "",
"responseData": {
"leaderboard": [
{
"userid": 1,
"username": "username1",
"companyname": "Working com 1",
"currentlevel": 1
},
{
"userid": 2,
"username": "username2",
"companyname": "Working com 1",
"currentlevel": 13
}
]
}
}
当我尝试使用不在数组中的结构时,代码可以工作,但在上面我得到一个 SyntaxError:missing ; firebug 控制台中的 before 语句错误。我做错了什么?
最佳答案
尝试将 dataType: 'jsonp'
更改为 dataType: 'json'
您收到的数据是json
而不是jsonp
。因此,出现了错误。
关于javascript - 语法错误: missing ; before statement Json array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30149475/