问题
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