Metoda jQuery get()
Przykład
Wyślij żądanie HTTP GET do strony i uzyskaj wynik z powrotem:
$("button").click(function(){
$.get("demo_test.asp", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
Definicja i użycie
Metoda $.get() ładuje dane z serwera za pomocą żądania HTTP GET.
Przykłady
Zażądaj "test.php", ale zignoruj zwrócone wyniki:
$.get("test.php");
Zażądaj "test.php" i wyślij dodatkowe dane wraz z żądaniem (zignoruj wyniki zwrócenia):
$.get("test.php", { name:"Donald", town:"Ducktown" });
Zażądaj "test.php" i przekaż tablice danych do serwera (zignoruj zwracane wyniki):
$.get("test.php", { 'colors[]' : ["Red","Green","Blue"] });
Poproś o "test.php" i zaalarmuj wynik żądania:
$.get("test.php", function(data){
alert("Data: " + data);
});
Składnia
$.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:
|