ajax+php为什么不能显示输入框的结果,请在线聊,代码如下
页面1.php代码如下:
<html>
<head>
<title>无标题文档</title>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function startRequest() {
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
var name=document.getElementById("name").value;
var pare="name="+name;
xmlHttp.open("POST","2.php",pare,true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencode");
xmlHttp.send(null);
}
function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
alert(xmlHttp.responseText);
}
}
}
</script>
</head>
<body>
<form method="post" id="form1">
<input type="text" name="name" id="name">
<input type="submit" name="Submit" value="提交" onClick="startRequest()">
</form>
</body>
</html>
页面2.php代码如下:
<?php
$name=$_POST['name'];
echo $name;
?>
目的只是想让把输入的内容显示在提示框里,我的代码哪里错了,请把正确的代码告知