【发布时间】:2012-01-18 01:02:18
【问题描述】:
无论我尝试在 jquery 的 ajax 方法中使用 dataType 'jsonp' 加载什么,我都会得到“错误”,但是对于相同的 json 内容,仅使用 'json' 可以正常工作。我需要使用 jsonp,因为我正在调用外部 API 来使用。
js方法:
$.ajax({
url: 'test3.json',
type: 'GET',
dataType: 'json',
data: {
action: 'APICALL',
ID: '59'
},
success: function(data, textStatus, xhr) {
console.log('success');
},
error: function(data, textStatus, xhr) {
console.log('error: '+textStatus);
console.log(data);
},
complete: function(data, textStatus, xhr) {
console.log('complete');
}
});
})
test3.json 文件:
{"symbol": "IBM", "price": "91.42"}
【问题讨论】:
-
您可以在浏览器中访问此
test3.json吗?如果是这样,请尝试完全限定的 url。 -
你还需要 dataType: 'jsonp' 以及回调
标签: javascript jquery ajax json