【问题标题】:Chrome extension xhr cross domain request gives error:"is not allowed by Access-Control-Allow-Origin."Chrome 扩展 xhr 跨域请求给出错误:“Access-Control-Allow-Origin 不允许。”
【发布时间】:2012-01-27 22:11:05
【问题描述】:

我似乎无法请求此网址: “https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=dogs”来自我的 popup.html。

我明白了:

XMLHttpRequest 无法加载https://ajax.googleapis.com/ajax/services/search/web? v=1.0&q=狗。 Access-Control-Allow-Origin 不允许来源 chrome-extension://nemobemncffjipfgpaffgiigbjhkpden。

这是我的清单:

{
"name": "My First Extension",
"version": "1.0",
"description": "The first extension that I made.",
"browser_action": {
"default_icon": "icon.png",
"popup":"popup.html"
},
"permissions": [
"tabs","http://*/","https://*/"
]
}

和我的代码:

$.ajax({
            type: 'GET', //making a get request
            url:   "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=dogs",
            success: function (data) {
              document.write(data);
            }
            });

请帮忙,谢谢。

【问题讨论】:

    标签: ajax google-chrome-extension xmlhttprequest cross-domain get-request


    【解决方案1】:

    查看我的 manifest.json 中的权限列:

    "permissions": ["tabs", "notifications", "http://*/*", "https://*/*"],
    

    所以,您的 url 格式错误,应该是“http:///”,而不是“http://*/”。

    【讨论】:

    • 由于某种原因,chrome 在单击更新时没有更新清单。无论如何,感谢您的帮助,它成功了。
    猜你喜欢
    • 1970-01-01
    • 2013-11-23
    • 2013-02-17
    • 1970-01-01
    • 2013-07-20
    • 2013-09-27
    • 2013-05-16
    • 2013-12-09
    相关资源
    最近更新 更多