在扩展名default_popup中使用aJax?

时间:2012-12-30 23:12:51

标签: ajax google-chrome jquery google-chrome-extension

我可以在Google Chrome扩展程序“default_popup”中以某种方式使用aJax。

我试过以下......

的manifest.json:

{
  "name": "My extension",
  "manifest_version": 2,
  "version": "1.0",
  "permissions": [
    "tabs", "http://*/*"
  ],
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*"],
      "js": ["jquery-1.8.3.min.js", "content.js"],
      "run_at": "document_end"
    }
  ]
}

popup.html:

<html>
<body>
<script>
$.ajax({
    type: "GET",
    url: "http://www.mysite.com/api.php"
}).done(function(response) {
    alert("work");
}).fail(function(response) {
    alert("doesn't work");
});
</script>
</body>
</html>

有没有人有任何想法如何做到这一点?

1 个答案:

答案 0 :(得分:0)

这是可能的,但您很可能必须使用JSONP。您可以使用已有的基础,因此不需要太多重构。

相关问题