2011-08-20 38 views
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地址。 任何想法?

+2

请注意:您应该使用'xmlHttp.onload'而不是'xmlHttp.onreadystatechange'。那么你不需要在你的处理程序中检查'readyState'。 –

回答