Chrome extension xhr cross domain request gives error:“is not allowed by Access-Control-Allow-Origin.”

此生再无相见时 提交于 2019-12-11 07:17:01

问题


I cant seem to request this url: "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=dogs" from my popup.html.

I'm getting:

XMLHttpRequest cannot load https://ajax.googleapis.com/ajax/services/search/web? v=1.0&q=dogs. Origin chrome-extension://nemobemncffjipfgpaffgiigbjhkpden is not allowed by Access-Control-Allow-Origin.

Here is my manifest:

{
"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://*/"
]
}

and my code:

$.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);
            }
            });

Help please, thanks.


回答1:


Look at the permission column in my manifest.json:

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

So, your url pattern is wrong, it should be "http:///", not "http://*/".



来源:https://stackoverflow.com/questions/8634874/chrome-extension-xhr-cross-domain-request-gives-erroris-not-allowed-by-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!