get() Method for ajax event - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:get


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


Parameter RequireDescription
URL Required.URL to request
data to send to the server along with the request
function(data,status,xhr) Optional. a function to run if the request succeeds
dataType Optional. data type of the server response. By default jQuery would do the guess.

function(data,status,xhr) parameters:

  • data - resulting data from the request
  • status - status of the request ("success", "notmodified", "error", "timeout", or "parsererror")
  • xhr - XMLHttpRequest object

Possible types for dataType:

  • "xml" - An XML document
  • "html" - HTML 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 a JavaScript object
  • "jsonp" - Loads in a JSON block using JSONP.


Request "test.php" and send some additional data along with the request (ignore return results):

$.get("test.php", { name:"Mary", town:"England" });

Request "test.php" and pass arrays of data to the server (ignore return results):

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

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

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

The following code shows how to request "test.php", but ignore return results:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<script src=""></script>
    });/* w  w  w  .  j  a v a  2s. com*/



Related Tutorials