一.jQuery.post( url, [data], [callback], [type] ) :使用POST方式來進行異步請求
參數:
url (String) : 發送請求的URL地址.
data (Map) : (可選) 要發送給服務器的數據,以 Key/value 的鍵值對形式表示。
callback (Function) : (可選) 載入成功時回調函數(只有當Response的返回狀態是success才是調用該方法)。
type (String) : (可選)官方的說明是:Type of data to be sent。其實應該為客戶端請求的類型(JSON,XML,等等)
這是一個簡單的 POST 請求功能以取代復雜 $.ajax 。請求成功時可調用回調函數。如果需要在出錯時執行函數,請使用 $.ajax。
示例代碼:?
Response.ContentType?
=
?
"
application/json
"
;Response.Write(
"
{result:?'
"
?
+
?Request[
"
Name
"
]?
+
?
"
,你好!(這消息來自服務器)'}
"
);
jQuery 代碼:
?
$.post(
"
Ajax.aspx
"
,?
{?Action:?
"
post
"
,?Name:?
"
lulu
"
?}
,?function?(data,?textStatus)
{?
//
?data?可以是?xmlDoc,?jsonObj,?html,?text,?等等.?
//
this;?
//
?這個Ajax請求的選項配置信息,請參考jQuery.get()說到的this?alert(data.result);?},?"json");
點擊提交:
這里設置了請求的格式為"json":
$.ajax()這個是jQuery 的底層 AJAX 實現。簡單易用的高層實現見 $.get, $.post 等。
這里有幾個Ajax事件參數:beforeSend ,success ,complete ,error 。
我們可以定義這些事件來很好的處理我們的每一次的Ajax請求。

$.ajax(
{url:?'stat.php',?
type:?'POST',?

data:
{Name:"keyun"},?
dataType:?'html',?
timeout:?1000,?

error:?function()
{alert('Error?loading?PHP?document');},?

success:?function(result)
{alert(result);}?
});??
本文來自: 腳本之家(www.jb51.net) 詳細出處參考:http://www.jb51.net/article/15095.htm
posted on 2009-10-28 14:14
becket_zheng 閱讀(487)
評論(0) 編輯 收藏 所屬分類:
網頁web前端技術