【php开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了php开源代码-18_3.php的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
<?php
if(isset($_GET["action"]) and $_GET["action"]=="getText"){
print $_POST["name"]."<br>".$_POST["age"];
exit();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD
HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>使用POST方法传输数据</title>
<?php
include_once("18_1.php");
?>
<script type="text/javascript">
function getContent(){
//定义要提交脚本的地址
var url = "18_3.php";
var action = "action=getText";
var name = document.getElementById("username").value;
var age = document.getElementById("age").value;
post = "name="+name+"&age="+age;
//使用GET方法提交数据
xmlHttp.open("POST",url+"?"+action,true);
//发送HTTP头信息
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//发送请求,此处与GET方法不同
xmlHttp.send(post);
//指定回调函数
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4){
var text = xmlHttp.responseText;
document.getElementById("show_content").innerHTML = text;
}
}
}
</script>
</head>
<body>
<p><div id="show_content">默认数据</div></p>
<form action="">
:<input type="text" value="" id="username"><br>
年龄:<input type="text" value="" id="age"><br>
<input type="button" value="取得
PHP程序中的数据" onclick="getContent()" />
</form>
</body>
</html>