Implementing Ajax with jQuery
Once again I would say jQuery is my favorite javascript library. Not because its tiny but because it makes the things easier for me. In Past i was only building ajax applications with regular xmlHttp code which is tough to build again and again differently for each application.
Thanks to jQuery it makes the things easier. jQuery have a couple of ajax related functions. jQuery.ajax is the main core function. It can do post,get requests or even getting the html content. jQuery also have sub functions , means you can individually call get post functions instead of main jQuery.ajax. Here is i m going to explain how easy is to use jQuery.ajax to build a basic ajax request.
$.ajax({
type: "POST",
url: "myPostPage.php",
data: {name : "ThinkFlick" , topic : "Web Design & Development"},
success: function(msg){
alert( "hey i am from myPostPage.php : " + msg );
}
});
As you can see I have requested a php page and give some parameters to it via http POST method. And whatever php page will output it will go straight to the success function’s msg parameter. You can do post requests, get requests, simply get an html page content, a javascript or json page. Its a collection of tools
You can pass some more parameters to this function, such as dataType which will tell you what type of data you are excepting. By default its text. You can request xml, json object too. You can also give it another function which is called error function that will be called if an error or timeout occurred during the ajax request. More info and full document of this function can be found at jQuery docs page.
Related posts
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.







[...] I have used jQuery because of its powerful ajax core function and it is very easy to implement. You never need to define any xmlhttp object. jQuery does that all for you. Here is a tutorial that explains how to perform ajax actions with jQuery. [...]