jQuery get() Metode
Contoh
Kirim permintaan HTTP GET ke halaman dan dapatkan hasilnya kembali:
$("button").click(function(){
$.get("demo_test.asp", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
Definisi dan Penggunaan
Metode $.get() memuat data dari server menggunakan permintaan HTTP GET.
Contoh
Minta "test.php", tetapi abaikan hasil pengembalian:
$.get("test.php");
Minta "test.php" dan kirim beberapa data tambahan bersama dengan permintaan (abaikan hasil pengembalian):
$.get("test.php", { name:"Donald", town:"Ducktown" });
Minta "test.php" dan berikan array data ke server (abaikan hasil pengembalian):
$.get("test.php", { 'colors[]' : ["Red","Green","Blue"] });
Minta "test.php" dan beri tahu hasil permintaan:
$.get("test.php", function(data){
alert("Data: " + data);
});
Sintaksis
$.get(URL,data,function(data,status,xhr),dataType)
Parameter | Description |
---|---|
URL | Required. Specifies the URL you wish to request |
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:
|