jQuery Ajax: $.post请求示例
leyangjun.html页面
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="http://www.likecs.com/jquery-2.0.0.min.js"></script>
<script>
$(document).ready(function(){
$("#sub").click(function(){
$.post("leyangjun.php",{name:$("#name").val()},function(data,textStatus){
$("#result").append("data:"+data.name);
$("#result").append("<br>age:"+data.age);
$("#result").append("<br>textStatus:"+textStatus);
},"json");
return false;
});
});
</script>
</head>
<body>
<form action="testPost.php" method="post">
<input type="text" >
<input type="submit" value="提交">
</form>
<h2>页面显示回来的内容</h2>
<div></div>
</body>
</html>
相应的页面leyangjun.php
<?php
echo json_encode(
array(
"name" => $_POST[\'name\'],
"age" => 110,
)
);
?