5 ways to use Ajax with jQuery

Posted By Venu Thomas

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: , , , ,

  •  
  • Share with others:

    Thanks for visiting us! If you enjoyed these icons please feel free to share them! Or if you want to know what's going on with WiseCodes.com, follow us!

    24 Responses to “5 ways to use Ajax with jQuery”

    1. [...] 5 ways to use Ajax with jQuery [...]

    2. 網站製作學習誌 » [Web] 連結分享 your flag on September 1st, 2009 at 6:12 PM
    3. Thanks for a great post and interesting comments. I found this post while surfing for some popular lyrics. Thanks for sharing this post.

    4. drake all night long lyrics your flag on May 15th, 2010 at 1:44 AM
    5. 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.

    6. jay z forever young lyrics your flag on May 18th, 2010 at 3:36 AM
    7. 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.

    8. the resistance lyrics your flag on June 8th, 2010 at 4:31 AM
    9. 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.

    10. justin bieber stuck in the moment lyrics your flag on June 16th, 2010 at 4:29 AM
    11. 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.

    12. is building a fence cost effective your flag on June 26th, 2010 at 12:06 AM
    13. 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.

    14. proven method getting my ex back your flag on August 7th, 2010 at 3:24 AM
    15. Searching for this for some time now – i guess luck is more advanced than search engines :)

    16. easy mafia wars cheats your flag on August 7th, 2010 at 4:29 AM
    17. 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.

    18. lawn renovation your flag on August 8th, 2010 at 9:39 AM
    19. Wouldn’t it be extraordinary if Jay Z and Beyonce had a party and we were all invited?!

    20. Odell Callejas your flag on August 8th, 2010 at 4:12 PM
    21. Nice site, I just dugg this keep up the good work!. . . . . .

    22. Dominic Brown Stats your flag on August 10th, 2010 at 4:30 PM
    23. Such a well written post.. Thnkx for sharing this post!

    24. get him back your flag on August 12th, 2010 at 7:52 AM
    25. Hi buddy, your blog’s design is simple and clean and i like it. Your blog posts are superb. Please keep them coming. Greets!!!

    26. how to break 80 your flag on August 12th, 2010 at 9:22 AM
    27. A topic near to my heart thanks, do you have a Facebook page for your site?

    28. Free Avatars your flag on August 12th, 2010 at 11:36 PM
    29. 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.

    30. chanel handbags your flag on August 14th, 2010 at 4:29 PM
    31. Do you suppose Justin and Kim are only friends or is there more to it? He’s so much younger than her!

    32. Trenton Owolabi your flag on August 14th, 2010 at 11:47 PM
    33. Great job on the blog, it looks outstanding. I am going to save it and will make sure to visit weekly

    34. Nuby your flag on August 21st, 2010 at 5:14 AM
    35. A subject close to my heart cheers, do you have a RSS feed I can use?

    36. g1 wallpaper your flag on August 23rd, 2010 at 2:37 PM
    37. 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.

    38. full movie downloads your flag on August 24th, 2010 at 10:26 PM
    39. 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.

    40. how to date men your flag on August 28th, 2010 at 9:18 PM
    41. A truly amazing article. Many thanks for sharing you?e wealth of Understanding with us once again. It? no wonder your Weblog does

    42. Venice Trevino your flag on August 28th, 2010 at 10:38 PM
    43. Searching for this for some time now – i guess luck is more advanced than search engines :)

    44. funniest wedding speech your flag on August 29th, 2010 at 1:59 AM
    45. Wonderful article. Gracias!

    46. Darryl Roehrick your flag on August 29th, 2010 at 2:11 AM
    47. Nice site. Thank you!

    48. Les Grumer your flag on August 29th, 2010 at 9:32 AM

    Leave a Reply

    Anti-Spam Protection by WP-SpamFree

    Locations of visitors to this page eXTReMe Tracker