欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript jQuery $.post $.ajax用法

 更新時(shí)間:2008年07月09日 19:05:39   作者:  
這是一個(gè)簡單的 POST 請(qǐng)求功能以取代復(fù)雜 $.ajax 。請(qǐng)求成功時(shí)可調(diào)用回調(diào)函數(shù)。如果需要在出錯(cuò)時(shí)執(zhí)行函數(shù),請(qǐng)使用 $.ajax。
jQuery.post( url, [data], [callback], [type] ) :使用POST方式來進(jìn)行異步請(qǐng)求


參數(shù): 

url (String) : 發(fā)送請(qǐng)求的URL地址. 

data (Map) : (可選) 要發(fā)送給服務(wù)器的數(shù)據(jù),以 Key/value 的鍵值對(duì)形式表示。 

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)該為客戶端請(qǐng)求的類型(JSON,XML,等等)

這是一個(gè)簡單的 POST 請(qǐng)求功能以取代復(fù)雜 $.ajax 。請(qǐng)求成功時(shí)可調(diào)用回調(diào)函數(shù)。如果需要在出錯(cuò)時(shí)執(zhí)行函數(shù),請(qǐng)使用 $.ajax。示例代碼:

Ajax.aspx:

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請(qǐng)求的選項(xiàng)配置信息,請(qǐng)參考jQuery.get()說到的this            alert(data.result);        }, "json");點(diǎn)擊提交: 

這里設(shè)置了請(qǐng)求的格式為"json":


$.ajax()這個(gè)是jQuery 的底層 AJAX 實(shí)現(xiàn)。簡單易用的高層實(shí)現(xiàn)見 $.get, $.post 等。

這里有幾個(gè)Ajax事件參數(shù):beforeSend ,success ,complete ,error 。我們可以定義這些事件來很好的處理我們的每一次的Ajax請(qǐng)求。

$.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);}

});

相關(guān)文章

最新評(píng)論