<?php echo "<pre>"; print_r($_POST); echo "</pre>"; ?>
建立 test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Ajax+jQuery入門</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.js"></script>
<script type="text/javascript">
$.post("test.php", { name: "John", age: "25" },function(result){
$("#div_test").html(result);
});
</script>
</head>
<body>
<div width="300" height="160" border="1" id="div_test"></div>
</body>
</html>
然後執行 test.html。這一頁其實只有一個空的 div 元素,但是執行之後可以看到 test.php 接收到的 post 內容:
Array
(
[name] => John
[age] => 25
)
參考:
http://www.w3school.com.cn/jquery/ajax_post.asp
沒有留言:
張貼留言