English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The $ .get() method uses an HTTP GET request to load data from the server.
$.get(URL, data, callback, dataType)
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 and see‹/›
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 and see‹/›
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 and see‹/›
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 and see‹/›
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 and see‹/›
Parameter | Description |
---|---|
URL | Specify the URL you want to request |
data | (Optional) Specify the data to be sent to the server along with the request |
callback | (Optional) Specify the callback function to be executed after the request is successful Parameters:
|
dataType | (Optional) Specify the data type required by the server response By default, jQuery performs automatic guessing Possible types:
|