欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

判斷請求頭中是否含有某屬性來判斷是否是ajax請求

 更新時間:2014年01月20日 17:08:29   作者:  
本文為大家介紹下如何判斷請求頭中是否含有某屬性來判斷是否時ajax請求,具體示例如下
復制代碼 代碼如下:

<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默認會發(fā)送一個含有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>

相關文章

最新評論