Access-Control-Allow-Origin不允许使用Origin?

时间:2013-02-20 04:15:50

标签: javascript google-chrome google-chrome-extension xmlhttprequest

我正在尝试使用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.

enter image description here

我想不出有什么理由发生这种情况。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您的Chrome-Extention是否有清单文件?看起来这就是问题,你还应该在那里设置你的跨域权限。

似乎randomId提及与未分配正确的扩展ID的扩展名有关。

相关问题