我正在尝试进行跨域脚本调用以从远程服务器获取一些JSON数据,我可以看到正在进行的请求以及使用Fiddler成功返回的数据,但调用失败,因为它无法解析JSON - JSON有效......
以下jquery ajax调用有什么问题吗?
jquery version = 1.7.1
$.ajax({
url: 'http://fooed.cloudapp.net/users?callback=?',
crossDomain: true,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
alert('success');
},
error: function(data) {
alert('error');
},
complete: function(xhr, data) {
if (xhr.status == 0)
alert('fail');
else
alert('success');
}
});
示例JSON:
[{ "ContentPreferences":[],
"Email":"mark.jones@somedomain.com",
"FirstName":"Mark",
"Id":"aa2f1944-e739-4329-9546-a21f52c02448",
"KnownAs":"Mark",
"LastName":"Jones",
"TimeStamp":"\/Date(1323804151906)\/"
}]
答案 0 :(得分:1)
您的json无效jsonp。它看起来应该是这样的:
foo([{ "ContentPreferences":[],
"Email":"mark.jones@somedomain.com",
"FirstName":"Mark",
"Id":"aa2f1944-e739-4329-9546-a21f52c02448",
"KnownAs":"Mark",
"LastName":"Jones",
"TimeStamp":"\/Date(1323804151906)\/"
}])
这意味着api不支持jsonp或需要与callback=?
不同的参数