3
我写的Firefox的扩展,它使用page-mod
模块运行包含JavaScript文件:FF扩展 - 让xmlhttp.status == 0
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
,即使不使用localhost
我使用IP地址。 任何想法?
请注意:您应该使用'xmlHttp.onload'而不是'xmlHttp.onreadystatechange'。那么你不需要在你的处理程序中检查'readyState'。 –