我正在尝试在 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.
我想不出为什么会发生这种情况。任何想法?