您的位置:首页 > Web前端 > JQuery

jQuery Ajax: $.post请求实例

2015-06-22 22:35 671 查看
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,

)

);

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: