我正在尝试为Mozilla Firefox创建一个插件。我为浏览器操作工具栏图标创建了一个弹出窗口。现在我只想点击弹出窗口中的按钮发出AJAX请求。我怎么能这样做?
我尝试了一些东西。
我的popup.html
<!DOCTYPE html>
<html>
<body>
<div id="demo">
<h2>The XMLHttpRequest Object</h2>
<button type="button" onclick="loadDoc()">Change Content</button>
</div>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "http://localhost/bestOfDeals", true);
xhttp.send();
}
</script>
</body>
</html>
AJAX请求返回一些JSON数据 但这不起作用。我做错了什么?
的manifest.json
{
"description": "description",
"manifest_version": 2,
"name": "Assistant",
"version": "1.0",
"homepage_url": "https://www.xxxxxxxx.com/",
"icons": {
"48": "icons/logo.png"
},
"background": {
"scripts": ["background.js"]
},
"permissions": [
"tabs",
"activeTab",
"notifications",
"desktop-notification": {
"description": "Needed for creating system notifications."
}
],
"browser_action": {
"default_icon": "icons/logo.png",
"default_title": "Assistant",
"default_popup": "popup/popup_menu.html"
},
"content_scripts": [
{
"matches": ["*://*/"],
"js": ["content_scripts/content-script.js"]
}
]
}