demo.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript">
//通过这个函数来异步获取信息
function Ajax(){
var xmlHttpReq =null;
if(xmlHttpReq.ActiveXObject){
xmlHttpReq=new ActiveXObject('Microsoft.XMLHTTP');
}else if(windows.XMLHttpRequest){
xmlHttpReq=new XMLHttpRequest();
}
if(xmlHttpReq!==null){
xmlHttpReq.open('GET','test.php',true);
xmlHttpReq.onreadystatechange=RequestCallback;
xmlHttpReq.send();
}
function RequestCallBack() {
if(xmlHttpReq.readyState==4){
if(xmlHttpReq.status==200){
document.getElementById('resText').innerHTML=xmlHttpReq.responseText;
}
}
}
}
</script>
</head>
<body>
<input type="button" value="Ajax提交" onclick="Ajax();" />
<div id="resText" ></div>
</body>
</html>
test.php
<?php
echo "Hello Ajax!";
?>