一.jQuery.post( url, [data], [callback], [type] ) :使用POST方式來進(jìn)行異步請求
參數(shù):
url (String) : 發(fā)送請求的URL地址.
data (Map) : (可選) 要發(fā)送給服務(wù)器的數(shù)據(jù),以 Key/value 的鍵值對形式表示。
callback (Function) : (可選) 載入成功時(shí)回調(diào)函數(shù)(只有當(dāng)Response的返回狀態(tài)是success才是調(diào)用該方法)。
type (String) : (可選)官方的說明是:Type of data to be sent。其實(shí)應(yīng)該為客戶端請求的類型(JSON,XML,等等)
這是一個(gè)簡單的 POST 請求功能以取代復(fù)雜 $.ajax 。請求成功時(shí)可調(diào)用回調(diào)函數(shù)。如果需要在出錯(cuò)時(shí)執(zhí)行函數(shù),請使用 $.ajax。
示例代碼:?
Response.ContentType?
=
?
"
application/json
"
;Response.Write(
"
{result:?'
"
?
+
?Request[
"
Name
"
]?
+
?
"
,你好!(這消息來自服務(wù)器)'}
"
);
jQuery 代碼:
?
$.post(
"
Ajax.aspx
"
,?
{?Action:?
"
post
"
,?Name:?
"
lulu
"
?}
,?function?(data,?textStatus)
{?
//
?data?可以是?xmlDoc,?jsonObj,?html,?text,?等等.?
//
this;?
//
?這個(gè)Ajax請求的選項(xiàng)配置信息,請參考jQuery.get()說到的this?alert(data.result);?},?"json");
點(diǎn)擊提交:
這里設(shè)置了請求的格式為"json":
$.ajax()這個(gè)是jQuery 的底層 AJAX 實(shí)現(xiàn)。簡單易用的高層實(shí)現(xiàn)見 $.get, $.post 等。
這里有幾個(gè)Ajax事件參數(shù):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) 詳細(xì)出處參考:http://www.jb51.net/article/15095.htm
posted on 2009-10-28 14:14
becket_zheng 閱讀(487)
評論(0) 編輯 收藏 所屬分類:
網(wǎng)頁web前端技術(shù)