创建xmlHttpRequest对象在FireFox中支持Ajax

    为了浏览器兼容,xmlhttp请求时,如果用到post方法,一定要先使用xhttp.setRequestHeader方法设计其http请求的head,只要将'Content-type'显式设置为'application/x-www-form-urlencoded',post方法就会有效了,否则很有可能出现一些奇怪的请求错误,比如411 content-length错误。。。
    还有,post方法时,不可以xmlhttp.send(null);如果没有发送应该用xmlhttp.send('');否则也会出错。。。

例:

<script language="javascript">
function getXMLHttpRequest()    
{
        var xmlHttpRequest;
        if (window.XMLHttpRequest) //For general cases.
        {
            //alert("0");
            xmlHttpRequest = new XMLHttpRequest();
        }
        else //For IE.
        {
            if (window.ActiveXObject)
            {
                //alert("1");
                xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        return xmlHttpRequest;
    }

function Show1(str)
{
     xmlHttp=new getXMLHttpRequest();
     xmlHttp.open('post','ajax.asp?id='+str,false);
     xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded;");      xmlHttp.send('');
     if(xmlHttp.status==200) document.getElementById("Info").innerHTML=xmlHttp.responseText;
}
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值