我想查詢在App Store上的應用程序給定的信息,但我不斷收到以下錯誤。我如何可以查詢在JavaScript中的iTunes搜索API?
XMLHttpRequest cannot load https://itunes.apple.com/lookup?id=<some-app-id>.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://www.<some-website>.co.uk' is therefore not allowed access. The response had HTTP status code 501.
我用來執行請求的代碼如下。
有誰知道在哪裏我可以去錯了嗎?
var config = {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With',
}
};
$http.get("https://itunes.apple.com/lookup?id=<some-app-id>", config).success(
function(data) {
// I got some data back!
}
);
丹尼爾與$ http.jsonp是更好的解決方案 – OMGPOP 2015-07-07 12:31:20