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。什么好主意吗?

内容脚本代码不能进行跨域请求-尝试使用Request模块:

https://addons.mozilla.org/en-US/developers/docs/sdk/1.1/packages/addon-kit/docs/request.html

与其在单独的脚本中编写代码并使用page-mod将其注入页面,不如在附加组件中的main.js脚本中实现请求。

最新更新