3 回答

TA貢獻1839條經驗 獲得超15個贊
xmlhttp 是如何創(chuàng)建的?
應該是你在火狐中,創(chuàng)建的xmlhttp對象,沒有成功。只采用IE下的創(chuàng)建方式
在IE與火狐中,創(chuàng)建xmlhttp對象的方法是不一樣的,現(xiàn)在給你個方法,用來創(chuàng)建這個對象,你可以試試:
function createxmlhttp(){//創(chuàng)建xmlhttp對象
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
xmlhttp = false;
}
}
if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
xmlhttp = new XMLHttpRequest();
if (xmlhttp.overrideMimeType){
xmlhttp.overrideMimeType('text/html');//設置MiME類別
}
}
return xmlhttp;
}
然后在你的AJAX方法中這樣調用:
var xmlhttp= createxmlhttp();
if(!xmlhttp){
alert("你的瀏覽器不支持XMLHTTP!!");
return;
}
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
以上是我的AJAX實現(xiàn)方法,經測試,火狐/IE 及其他瀏覽器 都好用
添加回答
舉報