jQuery post() Metode
Voorbeeld 1
Laai data vanaf die bediener met behulp van 'n HTTP POST-versoek:
$("button").click(function(){
$.post("demo_test.asp", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
Voorbeeld 2
Verander die teks van 'n <div>-element deur 'n AJAX POST-versoek te gebruik:
$("input").keyup(function(){
var txt = $("input").val();
$.post("demo_ajax_gethint.asp", {suggest: txt}, function(result){
$("span").html(result);
});
});
Definisie en gebruik
Die $.post()-metode laai data vanaf die bediener met behulp van 'n HTTP POST-versoek.
Sintaksis
$(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:
|