我已经成功从Google Extensions中的popup.html调用jQuery POST。但是,成功或错误回调函数尚未被调用。我在stackoverflow上搜索过,似乎这是因为域。Chrome扩展jQuery POST回调
作为一种解决方案,我尝试将chrome.extension.sendRequest发送到background.html页面,并让后台页面执行帖子。但是,background.html页面上的侦听器似乎没有收到请求。
在popup.html,我有
chrome.extension.sendRequest({test:'test123'}, function(response) {
alert('hello')
}
在background.html,我已经
chrome.extension.onRequest.addListener(
function(request, sender, resndResponse) {
console.log(request)
}
)
这是为什么不工作?还有其他解决方案吗?
那么,在弹出窗口中,当我打电话 '$ .post( “http:// localhost:8888 /”,{test:'test'},function(data){console.log('hi')})',帖子发生了,但console.log没有发生。我在权限下包含“http:// */*”。是否无法获得足够的权限来执行扩展的任何部分/页面中的回调函数? – user881185
@ user881185我很确定它不会允许你发布任何东西到8888端口。源端口(80)和目标端口应匹配(并且无法通过清单打开端口,它始终为80)。 – serg
将其设置为80也不起作用。 – user881185