jQuery get()Method

jQuery AJAX 方法jQuery AJAX Methods

Example

Send an HTTP GET request to a page and get back the result:

$("button").click(function(){ $.get("/try/ajax/demo_test.php",function(data,status){ alert("Data:" + data + "\nStatus:" + status); }); });

Try it yourself »

Definition and Usage

The $.get() method loads data from the server using an HTTP GET request.


Example

Request "test.php", but ignore the returned result:

$.get("test.php");

Request "test.php" and send some extra data along with the request (ignoring the returned result):

$.get("test.php", { name:"Donald", town:"Ducktown" });

Request "test.php" and pass an array of data to the server (ignoring the returned result):

$.get("test.php", { 'colors[]' : ["Red","Green","Blue"] });

Request "test.php" and alert the result of the request:

$.get("test.php", function(data){
alert("Data: " + data);
});


Syntax

$.get(URL,data,function(data,status,xhr),dataType)

Parameter Description
URL Required. Specifies the URL you need to request.
data Optional. Specifies the data sent to the server along with the request.
function(data,status,xhr) Optional. Specifies the function to run when the request succeeds.
Additional parameters:
  • data- Contains the result data from the request
  • status- Contains the status of the request ("success", "notmodified", "error", "timeout", "parsererror")
  • xhr- Contains the XMLHttpRequest object
dataType Optional. Specifies the expected data type of the server response.
By default, jQuery will make an intelligent guess.
Possible types:
  • "xml" - An XML document
  • "html" - HTML as plain text
  • "text" - A plain text string
  • "script" - Runs the response as JavaScript, and returns it as plain text
  • "json" - Runs the response as JSON, and returns it as a JavaScript object
  • "jsonp" - Load a JSON block using JSONP, adding a "?callback=?" to the URL to specify the callback


jQuery AJAX 方法jQuery AJAX Methods

Other Extensions