HTTP_X_REQUESTED_WITH


<html>
<head>
<script language="javascript">

function cl()
{
    var xmlhttp;

    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }


    xmlhttp.open("POST","ajax2.html",true);
    xmlhttp.setRequestHeader ("Content-Type","application/x-    www-form-urlencoded");
    //jquery YUI默认会发送一个含有HTTP_X_REQUESTED_WITH的HTTP请求头消息,因此,可以通过判断请求头中是否含有该属性来判断是否时ajax请求
    xmlhttp.setRequestHeader('HTTP_X_REQUESTED_WITH', 'HTTP_X_REQUESTED_WITH');
    xmlhttp.send();

    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            alert(xmlhttp.responseText);
        }
    }
}

</script>
</head>
<body>
    <input type="button" id="bt" name="bt" value="OK" onclick="cl();" />
</body>
</html>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM