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