post() 方法經過 HTTP POST 請求從服務器載入數據。 javascript
語法: php
$.post(url,data,success(data, textStatus, jqXHR),dataType)
get() 方法經過遠程 HTTP GET 請求載入信息 html
$.get(url,data,success(response,status,xhr),dataType)
POST和GET方式差很少,下面只舉get的例子。pos就只須要把get化成post
java
1、經過get方式請求加載 jquery
index.html ajax
<html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width"> <script type="text/javascript" src="js/jquery-1.7.2.js"></script> </head> <body> <a href="#" id="getData">獲取</a> <div id="content">這裏顯示ajax請求內容</div> </body> </html> <script> $("doucument").ready(function(){ $("#getData").click(function(){ $.get("ajax.php",{name:"lgx",sex:"boy"},function(result){ $("#content").html(result); }); }); }); </script>
ajax.php 服務器
<?php $name = $_GET['name']; $sex = $_GET['sex']; echo "your name is ".$name .'and sex is '.$sex;
//注意服務端要輸出數據,客戶端才能接收到。不可以用return哦 post