ajax+php为什么不能显示输入框的结果,请在线聊,代码如下

jzhpeng1 2008-12-15 08:50:17
页面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;
?>
目的只是想让把输入的内容显示在提示框里,我的代码哪里错了,请把正确的代码告知
...全文
99 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
jzhpeng1 2008-12-15
  • 打赏
  • 举报
回复
请加QQ;75450644在线聊

52,782

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧