源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

判断请求头中是否含有某属性来判断是否是ajax请求

  • 时间:2021-05-10 16:03 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:判断请求头中是否含有某属性来判断是否是ajax请求
[u]复制代码[/u] 代码如下:
<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>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部