www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons Ajax using jQuery get() and post() Methods Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
jQuery get() and post() methods allow us to send get and / or post HTTP requests to a web server and read back the web server generated result.

jQuery provides get() and post() methods to mimic the HTTP GET and POST requests.

These two methods are pretty similar in use. We call get() or post() directly on the jQuery class, as shown below:

jQuery.get(); // same as $.get();
jQuery.post(); // same as $.post();

In their simplest form, the get() and the post() methods take two parameters. The first is the URL of the page we wish to submit our request to and the second is a callback function that the jQuery invokes if the request succeeds.

For the following example make sure that you still have the file named "example.html", created in the last lesson, in the same directory where you save the example files.

Here is the example:

<script type = "text/javascript" >
$ ( function ()
        $ . get ( "example.html" , function (content , status )
    alert ( "AJAX call status: " + textStatus + ". Response: " + data );

The first parameter to the get() method, above, is the URL of a webpage and the second parameter is a callback function that is invoked, automatically, by jQuery if the get() call succeeds. The callback function takes two parameters i.e. the content of the request page and the textual status of the request. These two parameters are filled by the jQuery for us.

Normally we do not use the get() or the post() methods just to request a simple HTML page. We use these methods to pass in some parameters / information to the web server. The parameters are then processed by the web server with a piece of PHP, ASP, ASP.NET or any other server-side code, a result is generated and returned back.

The parameter passing is very simple. jQuery can take a map of GET or POST parameters to pass on to the server. This idea is illustrated in the following example:

<script type = "text/javascript" >
$ ( function ()
        $ . post ( "posthandler.php" ,
                id : "myid" ,
                password : "mypassword"
function ( content , status )
            alert ( "Response: " + content );

The post() method, above, takes three parameters i.e. URL of the webpage, map of post parameter and the callback function. The example above submits information to a PHP web page for processing and then displays the resulting content in an alert box.

PHP is a server-side programming language and technology. Millions of web applications have been created using this exiting technology. The discussion of PHP is out of the scope of this tutorial. If you are interested you can go through our PHP mySQL Programming Tutorial for the Beginners.

Our jQuery Tutorial for JavaScript Developers ends here. How did you find it? Please let us know at pickatutorial@yahoo.com

More jQuery Tutorials

Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.