You are on page 1of 7

30/10/23, 00:52 jQuery AJAX get() and post() Methods

 Tutorials  Exercises  Certificates  Services  Search...  Get Certified Sign Up Log in

HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT ❯
MYS
jQuery Set
jQuery Add
jQuery Remove
jQuery CSS Classes
jQuery css()
jQuery Dimensions

jQuery Traversing
jQuery - AJAX get() and post()
jQuery Traversing
jQuery Ancestors
Methods
jQuery Descendants
jQuery Siblings ❮ Previous Next ❯
jQuery Filtering

jQuery AJAX The jQuery get() and post() methods are used to request data from the server
with an HTTP GET or POST request.
jQuery AJAX Intro
jQuery Load
jQuery Get/Post
HTTP Request: GET vs. POST
jQuery Misc
Two commonly used methods for a request-response between a client and server
jQuery noConflict()
are: GET and POST.
jQuery Filters
GET - Requests data from a specified resource
jQuery Examples POST - Submits data to be processed to a specified resource

jQuery Examples
jQuery Editor
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp 1/7
30/10/23, 00:52 jQuery AJAX get() and post() Methods

GET is basically used for just getting (retrieving) some data from the server. Note:
 Tutorials  ExercisesThe Certificates
 GET methodmay Services 
return cached data.  Get Certified Sign Up Log in

HTML CSS JAVASCRIPT SQL canPYTHON


POST JAVA
also be used to get PHP HOWfrom
some data TO theW3.CSS C C++
server. However, C# method
the POST BOOTSTRAP REACT ❯
MYS
jQuery Set
NEVER caches data, and is often used to send data along with the request.
jQuery Add
jQuery Remove To learn more about GET and POST, and the differences between the two methods,
jQuery CSS Classes please read our HTTP Methods GET vs POST chapter.
jQuery css()
jQuery Dimensions
jQuery $.get() Method
jQuery Traversing
jQuery Traversing The $.get() method requests data from the server with an HTTP GET request.
jQuery Ancestors
jQuery Descendants
Syntax: COLOR
jQuery Siblings PICKER
$.get(URL,callback);
jQuery Filtering

The required URL parameter specifies the URL you wish to request.
jQuery AJAX
jQuery AJAX Intro The optional callback parameter is the name of a function to be executed if the
request succeeds.
jQuery Load

jQuery Get/Post
The following example uses the $.get() method to retrieve data from a file on the 
server:
jQuery Misc
jQuery noConflict()
jQuery Filters Example
jQuery Examples $("button").click(function(){
jQuery Examples $.get("demo_test.asp", function(data, status){

jQuery Editor
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp 2/7
30/10/23, 00:52 jQuery AJAX get() and post() Methods

alert("Data: " + data + "\nStatus: " + status);


 Tutorials  Exercises  Certificates 
}); Services   Get Certified Sign Up Log in
});
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT ❯
MYS
jQuery Set
jQuery Add Try it Yourself »
jQuery Remove
jQuery CSS Classes
jQuery css() The first parameter of $.get() is the URL we wish to request ("demo_test.asp").
jQuery Dimensions
The second parameter is a callback function. The first callback parameter holds the
content of the page requested, and the second callback parameter holds the status of
jQuery Traversing
the request.
jQuery Traversing
jQuery Ancestors Tip: Here is how the ASP file looks like ("demo_test.asp"):
jQuery Descendants
jQuery Siblings <%
response.write("This is some text from an external ASP file.")
jQuery Filtering
%>

jQuery AJAX
jQuery AJAX Intro
jQuery Load

jQuery $.post() Method


jQuery Get/Post

jQuery Misc
The $.post() method requests data from the server using an HTTP POST request.
jQuery noConflict()
jQuery Filters Syntax:

jQuery Examples $.post(URL,data,callback);


jQuery Examples
jQuery Editor
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp 3/7
30/10/23, 00:52 jQuery AJAX get() and post() Methods

The required URL parameter specifies the URL you wish to request.
 Tutorials  Exercises  Certificates  Services   Get Certified Sign Up Log in
The optional data parameter specifies some data to send along with the request.
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT ❯
MYS
jQuery Set The optional callback parameter is the name of a function to be executed if the
jQuery Add request succeeds.
jQuery Remove
The following example uses the $.post() method to send some data along with the
jQuery CSS Classes
request:
jQuery css()
jQuery Dimensions

jQuery Traversing Example


jQuery Traversing
$("button").click(function(){
jQuery Ancestors $.post("demo_test_post.asp",
jQuery Descendants {
jQuery Siblings name: "Donald Duck",
jQuery Filtering city: "Duckburg"
},
jQuery AJAX function(data, status){
alert("Data: " + data + "\nStatus: " + status);
jQuery AJAX Intro
});
jQuery Load });
jQuery Get/Post

Try it Yourself »
jQuery Misc
jQuery noConflict()
jQuery Filters
The first parameter of $.post() is the URL we wish to request
("demo_test_post.asp").
jQuery Examples
jQuery Examples Then we pass in some data to send along with the request (name and city).

jQuery Editor
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp 4/7
30/10/23, 00:52 jQuery AJAX get() and post() Methods

The ASP script in "demo_test_post.asp" reads the parameters, processes them, and
 Tutorials  Exercisesreturns
 Certificates
a result.  Services   Get Certified Sign Up Log in

HTML CSS JAVASCRIPT SQLthirdPYTHON


The JAVA
parameter is PHP function.
a callback HOW TO W3.CSS
The first callback C C++ holds
parameter C# theBOOTSTRAP REACT ❯
MYS
jQuery Set
content of the page requested, and the second callback parameter holds the status of
jQuery Add the request.
jQuery Remove
jQuery CSS Classes Tip: Here is how the ASP file looks like ("demo_test_post.asp"):
jQuery css()
jQuery Dimensions <%
dim fname,city
fname=Request.Form("name")
jQuery Traversing
city=Request.Form("city")
jQuery Traversing Response.Write("Dear " & fname & ". ")
jQuery Ancestors Response.Write("Hope you live well in " & city & ".")
jQuery Descendants %>
jQuery Siblings
jQuery Filtering

jQuery AJAX jQuery AJAX Reference


jQuery AJAX Intro
For a complete overview of all jQuery AJAX methods, please go to our jQuery AJAX
jQuery Load Reference.
jQuery Get/Post

jQuery Misc ❮ Previous Log in to track progress Next ❯


jQuery noConflict()
jQuery Filters

jQuery Examples
jQuery Examples
jQuery Editor
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp 5/7
30/10/23, 00:52 jQuery AJAX get() and post() Methods

 Tutorials  Exercises  Certificates  Services   Get Certified Sign Up Log in

HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT ❯
MYS
jQuery Set
jQuery Add
jQuery Remove  SPACES UPGRADE NEWSLETTER

jQuery CSS Classes


jQuery css()
jQuery Dimensions
GET CERTIFIED REPORT ERROR

jQuery Traversing
jQuery Traversing Top Tutorials Top References
jQuery Ancestors
HTML Tutorial HTML Reference
jQuery Descendants CSS Tutorial CSS Reference
JavaScript Tutorial JavaScript Reference
jQuery Siblings How To Tutorial SQL Reference
SQL Tutorial Python Reference
jQuery Filtering Python Tutorial W3.CSS Reference
W3.CSS Tutorial Bootstrap Reference
Bootstrap Tutorial PHP Reference
jQuery AJAX PHP Tutorial HTML Colors
Java Tutorial Java Reference
jQuery AJAX Intro C++ Tutorial Angular Reference
jQuery Tutorial jQuery Reference
jQuery Load
jQuery Get/Post Top Examples Get Certified
HTML Examples HTML Certificate
jQuery Misc CSS Examples
JavaScript Examples
CSS Certificate
JavaScript Certificate
How To Examples Front End Certificate
jQuery noConflict() SQL Examples SQL Certificate
jQuery Filters Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
jQuery Examples PHP Examples
Java Examples
Java Certificate
C++ Certificate
XML Examples C# Certificate
jQuery Examples jQuery Examples XML Certificate
jQuery Editor
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp 6/7
30/10/23, 00:52 jQuery AJAX get() and post() Methods

 Tutorials  Exercises  Certificates  Services   Get Certified Sign Up Log in

HTML CSS JAVASCRIPT SQL PYTHON


  JAVA
  PHP
FORUMHOW TO
ABOUT W3.CSS C C++ C# BOOTSTRAP REACT ❯
MYS
jQuery Set
jQuery Add W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
learning.
jQuery Remove Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full
correctness
jQuery CSS Classes of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and
privacy policy.
jQuery css()
jQuery Dimensions Copyright 1999-2023 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

jQuery Traversing
jQuery Traversing
jQuery Ancestors
jQuery Descendants
jQuery Siblings
jQuery Filtering

jQuery AJAX
jQuery AJAX Intro
jQuery Load
jQuery Get/Post

jQuery Misc
jQuery noConflict()
jQuery Filters

jQuery Examples
jQuery Examples
jQuery Editor
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp 7/7

You might also like