Chrome扩展jQuery POST回调

Chrome扩展jQuery POST回调,jquery,google-chrome,post,google-chrome-extension,Jquery,Google Chrome,Post,Google Chrome Extension,我已经成功地从Google Extensions中的popup.html调用了jQuery帖子。但是,尚未调用成功或错误回调函数。我在stackoverflow上搜索过,似乎这是因为域 作为一种解决方案,我尝试将chrome.extension.sendRequest发送到background.html页面,并让后台页面执行post。但是,background.html页面上的侦听器似乎没有收到请求 在popup.html中,我有 chrome.extension.sendRequest({te

我已经成功地从Google Extensions中的popup.html调用了jQuery帖子。但是,尚未调用成功或错误回调函数。我在stackoverflow上搜索过,似乎这是因为域

作为一种解决方案,我尝试将chrome.extension.sendRequest发送到background.html页面,并让后台页面执行post。但是,background.html页面上的侦听器似乎没有收到请求

在popup.html中,我有

chrome.extension.sendRequest({test:'test123'}, function(response) {
    alert('hello')
}
chrome.extension.onRequest.addListener(
    function(request, sender, resndResponse) {
        console.log(request)
    }
)
在background.html中,我有

chrome.extension.sendRequest({test:'test123'}, function(response) {
    alert('hello')
}
chrome.extension.onRequest.addListener(
    function(request, sender, resndResponse) {
        console.log(request)
    }
)

为什么这不起作用?还有其他解决方案吗?

它不起作用,因为警报不是调试扩展的好方法。将所有警报替换为
console.log
,尤其是在弹出窗口中,它只是静默地停止其余代码的执行

弹出页面和背景页面具有完全相同的权限,所以无论弹出页面中的任何内容是否有效,在背景页面中的行为都是完全相同的

因此,从删除所有警报开始,并确保您在清单中声明了域权限:

"permissions": [
  "http://destination.com/"
],

假设代码的其余部分是正确的,那就足够了。

谢谢您的帮助。显然我很愚蠢,
$.post()
没有调用success函数的原因是我让Tornado发回了一个字符串而不是JSON对象…

在弹出窗口中,当我调用
$.post(“http://localhost:8888/“,{test:'test'},函数(数据){console.log('hi')}
,post发生,但是console.log不会发生。我在权限下包含了“http://*/*”。是否无法获得足够的权限在扩展的任何部分/页面中执行回调函数?@user881185我很确定它不允许您将任何内容发布到8888端口。源(80)和目标的端口应该匹配(并且您不能通过清单打开端口,它总是80)。@user881185请发布更多代码。您在控制台日志中看到任何错误吗?您是否在“网络”选项卡中看到正在发送的请求?反应如何?