Phương thức jQuery post ()
ví dụ 1
Tải dữ liệu từ máy chủ bằng yêu cầu HTTP POST:
$("button").click(function(){
$.post("demo_test.asp", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
Ví dụ 2
Thay đổi văn bản của phần tử <div> bằng cách sử dụng yêu cầu AJAX POST:
$("input").keyup(function(){
var txt = $("input").val();
$.post("demo_ajax_gethint.asp", {suggest: txt}, function(result){
$("span").html(result);
});
});
Định nghĩa và Cách sử dụng
Phương thức $ .post () tải dữ liệu từ máy chủ bằng cách sử dụng yêu cầu HTTP POST.
Cú pháp
$(selector).post(URL,data,function(data,status,xhr),dataType)
Parameter | Description |
---|---|
URL | Required. Specifies the url to send the request to |
data | Optional. Specifies data to send to the server along with the request |
function(data,status,xhr) | Optional. Specifies a function to run if the request succeeds Additional parameters:
|
dataType | Optional. Specifies the data type expected of the server response. By default jQuery performs an automatic guess. Possible types:
|