Technical

Ajax using JQuery


Using JQuery, we can simply make Ajax call. JQuery provides us simple methods to make Ajax call using GET or POST. We can use any of these HTTP methods to make Ajax request using JQuery.

1. $.get() : Load a remote page using an HTTP GET request.

Syntax: $.get(String url, Map params, Function callback) returns XMLHttpRequest

Example 1: simple ajax call using $.get()

$.get(“test.php”);

Example 2: ajax call with parameter in query string

$.get(“test.php”, { name: “mohit”, age: “24” } );

Example 3: ajax call handles response

$.get(“test.php”, function(data){
alert(“Ajax call complete”);
});

Example 4: ajax call with parameter in query string and handles response

$.get(“test.php”,
{ name: “mohit”, age: “24” },
function(data){
alert(“Ajax call complete”);
}
);

2. $.post() : Load a remote page using an HTTP POST request.

Syntax: $.post(String url, Map params, Function callback) returns XMLHttpRequest

Example 1: simple ajax call using $.post()

$.post(“test.php”);

Example 2: ajax call with parameter

$.post(“test.php”, { name: “mohit”, age: “24” } );

Example 3: ajax call handles response

$.post(“test.php”, function(data){
alert(“Ajax call complete”);
});

Example 4: ajax call with parameter and handles response

$.post(“test.php”,
{ name: “mohit”, age: “24” },
function(data){
alert(“Ajax call complete”);
}
);

Isn’t it simple to use JQuery for AJAX…

Advertisements

4 thoughts on “Ajax using JQuery

  1. in all your examples, you have called local pages. how to call the remote pages. when i call the remote pages a javascript error occurs – ” Access Denied to remote URI”.

    how to go about it?
    any help will be greatly appreciated.

    sunil

  2. @Sunil: You can make ajax request only to your hosting site. You can’t make ajax request directly to any remote site. One way is to use proxy servers to make ajax request.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s