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…
hi….mohit…how ru..i have some query abt ajax can u plz help me…hope to get ur reply bk…
@shweta: Whats your issue?
Catch me on mkbansal007@gmail.com
Regards,
mohit
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
@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.
can you give an example for it?