我得到的 JSON 响应为
{
"title": "Some title",
"link": "http://google.com",
"desc": "Some description",
"items": [{"title":"some title"}]
}
我使用 $ajax 来获取响应
$.ajax({
url : url,
type: 'post',
dataType:'jsonp',
success : function(data) {
console.log(json)
}
});
};
它给了我一个“无效标签”错误。由于响应来自不同的服务器,我应该使用 JSONP 吗?我用 google 搜索了一下,很多人建议使用 ParseJSON。但是如何解析它,因为 console.log 没有触发。
最佳答案
传递到 success 函数的 data
变量是响应。 console.log(json)
将是未定义的,因为变量 json
不存在。
$.ajax({
url : url,
type: 'post',
dataType:'json',
success : function(data) {
console.log(data);
}
});
关于jquery - 如何在ajax成功中解析JSON对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11793770/