Chrome拡張機能でXHRを使用してYahooから天気情報を取得しようとしています:
$.ajax({
url: "https://weather.yahooapis.com/forecastrss?w=" + 250226 + "&u=c",
dataType: 'xml',
success: function(data) {
console.log(data);
}
});
そして、次のスクリプトを使用してクロスオリジンの許可をリクエストしました。
$("button").click(function(){
chrome.permissions.request({
origins: ['*://weather.yahooapis.com/*']
}, function(granted) {
if (granted) {
console.log("Success creating permission."); //successful
} else {
console.log("Not successful.");
}
});
ただし、それでも次のようなエラーが表示されます。
XMLHttpRequest cannot load http://weather.yahooapis.com/forecastrss?w=2502265&u=c. Origin chrome-extension://randomid is not allowed by Access-Control-Allow-Origin.
そして、私はこれが起こっている理由を考えることはできません。何か案が?