FF 扩展 - 获取 xmlhttp.status==0
我正在为 Firefox 编写一个扩展,它使用 page-mod
模块来运行一个 JavaScript 文件,其中包含:
function handleServerResponse() {
if (xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
//some code
}
else {
alert("Error during AJAX call. Please try again");
}
}
}
var xmlHttp = new XMLHttpRequest();
var txtname = document.getElementById("txtname");
xmlHttp.open("POST","http://localhost:8080/Jelly/GetStuff",true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.send("url=" + document.URL);
我不断收到 xmlhttp.status==0
而不是200
,即使我使用的是 IP 地址而不是 localhost
。
有什么想法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
内容脚本代码无法执行跨域请求 - 请尝试使用请求模块:
https://addons.mozilla.org/en-US/developers/docs/sdk/1.1/packages/addon-kit/docs/request.html
而不是在单独的脚本并使用 page-mod 将其注入到页面中,您可以在附加组件的 main.js 脚本中实现请求。
Content script code can't do cross-domain requests - try using the Request module instead:
https://addons.mozilla.org/en-US/developers/docs/sdk/1.1/packages/addon-kit/docs/request.html
Instead of writing the code in a separate script and injecting it into a page using a page-mod, you can implement the request in the main.js script in your add-on.