需要实现点击一个按钮,然后在按钮下方出现ajax提交。
请求的是一个test。php ,现在不知道那个php文件要如何写,那位仁兄指点下<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>第一个ajax例子</title>
<script type="text/javascript" >
function Ajax(){
var xmlHttpReq = null;
if(window.ActiveXObject){
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttpReq = new XMLHttpRequest();
}
if(xmlHttpReq){
xmlHttpReq.open("GET","test.php",true);
xmlHttpReq.onreadystatechange = requestCallBack;
xmlHttpReq.send(null);
}
function requestCallBack(){
if(xmlHttpReq.readysate == 4){
if(xmlHttpReq.status == 200){
document.getElementbyId("resText").innerHTML = xmlHttpReq.responseText;
}
}
}
}
</script>
</head>
<body>
<input type="button" value="Ajax提交" noclick="Ajax()"/>
<div id="resText"></div>
</body>
</html>