我在第二次使用新的XMLHttpRequest()在從頁面上的文本框事件調用的JavaScript代碼中出現錯誤。 我的JavaScript發現從sql的文本輸入的建議做,我使用xmlhttprequest,它做的很好,當它是第一次,但是當我繼續在文本框中鍵入我收到「typeerror:xmlhttprequest不是一個costructor」(此錯誤發生僅在Firefox)頁面上的多個xmlhttprequest
這是我的代碼 功能fnNull(){}; 功能changeofstate(){ 如果(XMLHttpRequest.readyState == 4){ 任何 ;
} XMLHttpRequest.onreadystatechange = fnNull(); (){ } var WebURL =「這裏的網址」; XMLHttpRequest = CreateXmlHttpObject(changeOfState); XMLHttpRequest.open(「GET」,WebURL,true); XMLHttpRequest.send(null); XMLHttpRequestt.abort(); }
}
功能CreateXmlHttpObject(處理){
var objXmlHttpReq = null;
var Req = null;
if (navigator.userAgent.indexOf("Opera")>=0)
{
return ;
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{
var strName="Msxml2.XMLHTTP";
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP";
}
try
{
objXmlHttpReq=new ActiveXObject(strName);
objXmlHttpReq.onreadystatechange = handler;
return objXmlHttpReq;
}
catch(e)
{
return ;
}
}
if (navigator.userAgent.indexOf("Mozilla") >= 0) {
try
{
if (Req == null) {
Req = new XMLHttpRequest();
}
Req.onload = handler;
Req.onerror = handler;
return Req;
}
catch (e) {
alert(e);
alert(Req.responseText)
alert(e);
return;
}
}
}
好吧,我把它命名爲需求,這是你的意思? – sweetyears 2010-11-09 16:59:50
也當我在錯誤控制檯看,我看到幾個這種日誌。未捕獲的異常索引或大小,則允許量的代碼負或更高:1個nsresult:「0x80530001納秒錯誤DOM索引尺寸誤差 – sweetyears 2010-11-09 17:06:37
的XMLHttpRequest = CreateXmlHttpObject(changeOfState);應變種REQ = CreateXmlHttpObject(changeOfState); – DivineGod 2010-11-09 19:03:55