<ht
ML>
<head>
<script language="javascript">
function cl()
{
VAR XMlhtt
p; if (window.XMLHtt
PRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.o
PEn("POST","ajax2.html",true);
xmlhttp.setRequestHeader ("Content
-type","application/x- www-form-url
encoded");
//
jquery YUI默认会发送一个含有HTTP_X_REQUESTED_W
ITH的HTTP请求头消息,因此,可以通过判断请求头中
是否含有该属性来判断是否时ajax请求
xmlhttp.setRequestHeader('HTTP_X_REQUESTED_WITH', 'HTTP_X_REQUESTED_WITH');
xmlhttp.send();
xmlhttp.onready
statechange=function()
{
if(xmlhttp.readyState
==4
&& xmlhttp.status==200)
{
alert(xmlhttp.responseText);
}
}
}
</script>
</head>
<body>
<input type="button" id="
BT" n
ame="bt" value="OK" onclick="cl();" />
</body>
</html>