The people of Nettuts publishes an interesting article on using jQuery with Ajax. Specifically the 5 ways that jQuery allows us to send asynchronous requests.
- $.load()
- $.get()
- $.post()
- $.getJSON()
- $.getScript()
$. load ()
This is the feature I like most about jQuery already makes one of the most common tasks of developing with Ajax is as simple and straightforward as we shall see in this example:
$("#div_links").load("/Main_Page #jq-p-Getting-Started li");
This example brought to the documentation page on jQuery, it manages to launch a request to the URL /Main_Page (usa URL Rewrite) HTML response and take the #jq-p-Getting-Started li and inserted into #div_links
Just great, comfortable and fast.
$. get ()
This is the simple function with which we can launch the server via GET requests Ajax.
$.get("test.cgi", { name: "Venu", time: "7pm" },
function(data){
alert("Data Loaded: " + data);
});
By passing 3 options, 2 of which are options (rather conditional) you can request to launch the file (1) with parameters (2) and treat the response through a callback (3rd).
$. post ()
Like the above, this feature lets you send POST requests using Ajax.
$.post("test.php", { name: "Venu", time: "7pm" },
function(data){
alert("Data Loaded: " + data);
});
As easy as above.
$. getJSON ()
Although the above are able to specify the type of return, the best option is to use this method to obtain the response in JSON evaludada the callback function.
$.getJSON("test.js", { name: "Venu", time: "7pm" }, function(json){
alert("JSON Data: " + json.users[3].name);
});
Taking into account the browser, the object will use native JSON or use a system based on eval().
$. getScript ()
Although technically not an Ajax request is a request to the server and therefore has a place in the post.
$.getScript("test.js", function(){
alert("Script loaded and executed.");
});
With this method we can load a file asynchronously using JavaScript and the parameter (2) callback can execute Javascript code that is using the js file that we want to load (1).
Tags: Ajax, JAVASCRIPT, jQuery, Learn, OpenSource
[...] 5 ways to use Ajax with jQuery [...]
Thanks for a great post and interesting comments. I found this post while surfing for some popular lyrics. Thanks for sharing this post.
Awesome post, hey I came across this post while surfing the web for Pop Lyrics. Thanks for sharing I’ll post this to my facebook about this too.
This is a good post, I stumbled across your story while looking for rock lyrics. Thanks for sharing, I’ll be sure to recommend this site to others.
Hey this is a great post. I’m going to email this to my buddies. I stumbled on this while surfing for some lyrics, I’ll be sure to come back. thanks for sharing.
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
It’s the first time I have heard that in Macedonia, obits are an unusual observe. You have wonderfully written the post. I have liked your way of writing this. Thanks for sharing this.
Searching for this for some time now – i guess luck is more advanced than search engines
I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success.
Wouldn’t it be extraordinary if Jay Z and Beyonce had a party and we were all invited?!
Nice site, I just dugg this keep up the good work!. . . . . .
Such a well written post.. Thnkx for sharing this post!
Hi buddy, your blog’s design is simple and clean and i like it. Your blog posts are superb. Please keep them coming. Greets!!!
A topic near to my heart thanks, do you have a Facebook page for your site?
I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work.
Do you suppose Justin and Kim are only friends or is there more to it? He’s so much younger than her!
Great job on the blog, it looks outstanding. I am going to save it and will make sure to visit weekly
A subject close to my heart cheers, do you have a RSS feed I can use?
This website is really a walk-through for all the information you wanted about this and didn’t know who to ask. Look here, and you will really discover it.
Aw, this was a really quality post. In theory I’d like to write like this too – taking time and real effort to make a good article… but what can I say… I procrastinate alot and never seem to get something done.
A truly amazing article. Many thanks for sharing you?e wealth of Understanding with us once again. It? no wonder your Weblog does
Searching for this for some time now – i guess luck is more advanced than search engines
Wonderful article. Gracias!
Nice site. Thank you!