manifest.json 中添加可信域名
"permissions": [
"http://www.sunzhongwei.com/"
],
事件逻辑中
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.sunzhongwei.com/some_api", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
document.getElementById("resp").innerHTML = xhr.responseText;
...
}
}
xhr.send();
如果想使用 jquery 的 ajax 只需要在插件的 html 中引入 jquery 即可。
参考
https://developer.chrome.com/extensions/xhr