Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery get() method

jQuery get() method

jQuery AJAX methods jQuery AJAX methods

Example

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

$

(

"

button

"

)

.

click

(

function

(

)

{

$.

get

(

"

/try/ajax/demo_test.php

"

,

function

(

data

,

status

)

{

alert

(

"

Data:

"

data

"

\n

Status:

"

status

)

;

}

)

;

}

)

;

Try it »


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 with the request (ignore the returned result):

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

Request "test.php" and pass an array of data to the server (ignore 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)

Parameters Description
URL Required. Specifies the URL you want to request.
data Optional. Specifies the data to send to the server along with the request.
function(data,status,xhr) Optional. Specifies the function to run when the request succeeds.
 额外的参数:       

 
  • data - Contains the resulting 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 makes an intelligent guess. Possible types: |

    jQuery AJAX methods jQuery AJAX methods