页面无刷新与服务端交互:
1 ajax+php
2 iframe +php 实现
第二种的实现方法:
test.html文件
<html>
<head>
<script>
function show(msg){
// document.getElementById("content").innerHTML=msg;
document.getElementById("content").innerHTML=msg;
}
</script>
</head>
<body>
<div id="content" style="width:200px;height:200px;border:1px solid #fafafa"></div>
<form action="test.php" method="get" target="postdata">
<input type="text" name="uname" size="30" maxlength="5" >
<input type="submit" value="say Hello" />
</form>
</body>
<iframe width="50" height="80" name="postdata"></iframe>
</html>
test.php 服务器端脚本文件:
<?php
$uname =$_GET['uname'];
echo "<script>window.parent.show('".$uname."');</script>";
?>