Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

jQuery get() Method

❮ jQuery AJAX Methods

Example

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

$("button").click(function(){
  $.get("demo_test.asp", function(data, status){
    alert("Data: " + data + "\nStatus: " + status);
  });
});
Try it Yourself »

Definition and Usage

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


Examples

Request "test.php", but ignore return results:

$.get("test.php");

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

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

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){
  alert("Data: " + data);
});


Syntax

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

Parameter Description
URL Required. Specifies the URL you wish to request
data Optional. Specifies data to send to the server along with the request
function(data,status,xhr) Optional. Specifies a function to run if the request succeeds
Additional parameters:
  • data - contains the resulting data from the request
  • status - contains the status of the request ("success", "notmodified", "error", "timeout", or "parsererror")
  • xhr - contains the XMLHttpRequest object
dataType Optional. Specifies the data type expected of the server response.
By default jQuery performs an automatic 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 a JavaScript object
  • "jsonp" - Loads in a JSON block using JSONP. Will add an "?callback=?" to the URL to specify the callback

❮ jQuery AJAX Methods

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.