HTML页面
<html>
<head>
</head>
<body>
<form action="7.php">
<input type="text" name="name">
<input type="text" name="pass">
<input type="text" name="age">
<input type="button" value="提交" onclick="a();">
</form>
<script src="js\jquery-1.11.2.min.js"></script>
<script>
function a(){
var cont=$("input").serialize();
$.ajax({
url:"7.php",
type:'post',
data:cont,
success:function (data){
var res = eval("(" + data + ")");//转为Object对象
document.write("name:"+res["name"]+"<br>");
document.write("pass:"+res["pass"]+"<br>");
document.write("age:"+res["age"]+"<br>");
}
})
}
</script>
</body>
</html>
PHP页面
<?php
$name=$_POST["name"];
$pass=$_POST["pass"];
$age=$_POST["age"];
$arr=array("name"=>$name,"pass"=>$pass,"age"=>$age);
$arr=json_encode($arr);
echo $arr;
?>