English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery get() method

jQuery-Ajax-Methode

$.get() method uses HTTP GET requests to load data from the server.

Syntax:

$.get(URL, data, callback, dataType)

Instance

This example retrieves the requested HTML code segment and inserts it into the page:

$("button").click(function(){
  $.get("ajax_get.php", function(data){
    $("#output").html(data);
  });
});
Test it out‹/›

Request the ajax_get.php page and send some other data:

$("button").click(function(){
  $.get("ajax_get.php", {fname:"Seagull", lname:"Anna"}, function(data){
    $("#output").html(data);
  });
});
Test it out‹/›

Request the ajax_get.php page, send some other data, and display an alert status message:

$("button").click(function(){
  $.get("ajax_get.php", {fname:"Seagull", lname:"Anna"}, function(data, status){
    $("#output").html(data);
    alert(status);
  });
});
Test it out‹/›

Request the demo.json file and insert it into the page:

$("button").click(function(){
  $.get("demo.json", function(data){
    let myObj = JSON.parse(data);
    $("#output").html(myObj.name);
  });
});
Test it out‹/›

Request json_demo that returns data in json format1.php file:

$("button").click(function(){
  $.get("json_demo1.php", function(data){
    let myObj = JSON.parse(data);
    $("#output").html(myObj.name);
  });
});
Test it out‹/›

Parameter value

ParameterDescription
URLSpecify the URL you want to request
data(Optional) Specify the data to be sent to the server along with the request
callback(Optional) Geben Sie die Callback-Funktion an, die nach dem Erfolg der Anfrage ausgeführt wird

Parameter:

  • data-Enthält die Ergebnisse der Anfrage

  • status-Enthält den Status der Anfrage ("success", "notmodified", "error", "timeout", oder "parsererror")

  • xhr-Enthält den XMLHttpRequest-Objekt

dataType(Optional) Geben Sie den erforderlichen Datentyp der Serverantwort an
Standardmäßig führt jQuery eine automatische Vorhersage durch

Mögliche Typen:

  • "xml"-Ein XML-Dokument

  • "html"-HTML als reiner Text

  • "text"-Reiner Textstring

  • "script"-Führen Sie die Antwort als JavaScript aus und geben Sie sie im reinen Textformat zurück

  • "json"-Führen Sie die Antwort als JSON aus und geben Sie ein JavaScript-Objekt zurück

  • "jsonp"-Laden Sie JSON-Blöcke mit JSONP. Fügen Sie die URL "?callback = ?" hinzu, um den Callback anzugeben

jQuery-Ajax-Methode