Chrome扩展xhr跨域请求提供错误:“Access-Control-Allow-Origin不允许”。 [英] Chrome extension xhr cross domain request gives error:"is not allowed by Access-Control-Allow-Origin."

查看:2786
本文介绍了Chrome扩展xhr跨域请求提供错误:“Access-Control-Allow-Origin不允许”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我得到:

XMLHttpRequest无法加载 https://ajax.googleapis.com/ajax/services/search/web ? v = 1.0& q =狗。

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.

以下是我的清单:

{
"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);
            }
            });

请帮助。

推荐答案

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

Look at the permission column in my manifest.json:

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

所以,你的url模式是错误的,应该是http:// / ,而不是http:// * /。

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

这篇关于Chrome扩展xhr跨域请求提供错误:“Access-Control-Allow-Origin不允许”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆