判断请求头中是否含有某属性来判断是否是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默认会发送一个含有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>
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
7月15日笔试总结
测验项目:3C数码商城+简答题+选择题测验时间:3小时不足之处:简答题3道题留白,完全不懂,仍需复习,一道题简写...
[阅读全文]
-
-
-
-
-
原生AJAX
AJAXAJAX 是指一种创建交互式、快速动态网页应用的网页开发技术,无需重新加载整个网页的情况下,能够更新部...
[阅读全文]
-
-
网友评论