我有一个网页,在调用时会返回此 JSON:
[{"id":"53","desc":"Roberts"}]
我正在使用这个 jQuery 通过 AJAX 调用它:
$.ajax ({
url: rootPath + "data/topology/stations",
dataType: 'json',
data: { areaID: $("#lbxArea").val () },
success: function (data) {
// Use data for actions
},
error: function (jqXHR, textStatus, errorThrown) {
alert (textStatus);
alert (errorThrown);
}
});
我使用 Firebug 来确认返回的数据就是我放在上面的数据。尽管如此,我还是陷入了 error
回调中,首先在警报框中看到了 parsererror
,然后我看到了
SyntaxError: JSON.parse: expected property name or '}'
我尝试让服务返回
{"list":[{"id":"53","desc":"Roberts"}]}
但这并没有改变任何事情。
最佳答案
响应内容类型是什么?! 尝试使用以下方法测试此响应:
Getting the response content-type from jQuery.Post
也尝试不使用 dataType: 'json' 并检查返回!
关于javascript - jQuery JSON 解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7040705/