jquery.post( url, [ data ], [ success(data, textstatus, xmlhttprequest) ], [ datatype ] )
returns: xmlhttprequest
jquery.post( url, [ data ], [ success(data, textstatus, xmlhttprequest) ], [ datatype ] )
烏拉字串,其中包含的url的請求被發送。
dataa地圖或字串,發送到伺服器的請求。
success(data, textstatus, xmlhttprequest)a callback function that is executed if the request succeeds.
datatypethe type of data expected from the server.
this is a shorthand ajax function, which is equivalent to:
$.ajax({
type: 'post',
url: url,
data: data,
success: success
datatype: datatype
});
這一成功是通過回呼函數返回的資料,這將是一個xml根項目或文本字串根據響應的mime類型。它還通過了響應文本的地位。
在jquery 1.4,成功回呼函數也是通過xmlhttprequest對象。
大多數實現將指定一個成功的處理常式:
$.post('ajax/test.html', function(data) {
$('.result').html(data);
});
examples:
例如:請test.php教程網頁,但忽略了返回結果。
$.post("test.php");
example:
request the test.php page and send some additional data along (while still ignoring the return results).
請求test.php網頁,發送一些額外的資料沿(同時仍忽略了返回結果)。
$.post("test.php", { name: "john", time: "2pm" } );
example: pass arrays of data to the server (while still ignoring the return results).
$.post("test.php", { 'choices[]': ["jon", "susan"] });
example: send form data using ajax requests
$.post("test.php", $("#testform").serialize());
example: alert out the results from requesting test.php (html or xml, depending on what was returned).
$.post("test.php", function(data){
alert("data loaded: " + data);
})
;example: alert out the results from requesting test.php with an additional payload of data (html or xml, depending on what was returned).
$.post("test.php", { name: "john", time: "2pm" },
function(data){
alert("data loaded: " + data);
});example: gets the test.php page content, store it in a xmlhttpresponse object and applies the process() 網頁特效 function.
$.post("test.php", { name: "john", time: "2pm" },
function(data){
process(data);
}, "xml");
example: gets the test.php page contents which has been returned in json format ()
$.post("test.php", { "func": "getnameandtime" },
function(data){
alert(data.name); // john
console.log(data.time); // 2pm
}, "json");