我在写一个chrome插件,用来做某个网站的查词翻译,现在需要调用扇贝的api
用原生js写的ajax:
var url = "https://api.shanbay.com/bdc/search/?word=dog";
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var res = JSON.parse(xmlhttp.responseText);
console.log(res);
}
};
xmlhttp.open("GET", url);
xmlhttp.send();
每次查询的时候就会报错
XMLHttpRequest cannot load https://api.shanbay.com/bdc/s... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'chrome-extension://coknhbkedmkppmjkdjfkbcndclocbbnh' is therefore not allowed access.
昨天调用的时候还没有任何问题
请问该如何解决
做 Chrome 插件有 API 能跨域的,看下文档
http://www.cnblogs.com/dojo-l...
可以在插件配置的json里面申明一下你需要跨的域,貌似是申明成*就能跨任何域的,你查查文档。
chrome 可以试下插件 cors plugin