jQuery Ajax: $.post请求示例
leyangjun.html页面
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="./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" name="name" id="name" >
<input type="submit" id="sub" value="提交">
</form>
<h2>页面显示回来的内容</h2>
<div id="result"></div>
</body>
</html>
相应的页面leyangjun.php
<?php
echo json_encode(
array(
"name" => $_POST['name'],
"age" => 110,
)
);
?
>
本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5038299.html,如需转载请自行联系原作者