Please navigate to the bottom of the page for Table of Contents

Thursday, June 2, 2011

jQuery AJAX functions part 1–the load() method

jQuery is rapidly gaining popularity in many web applications and most of the modern frameworks (including ASP.NET) are providing official support for this lightweight and powerful framework. As such, most of the web developer and SDET interviews now make sure that the interviewee knows and understands the jQuery concepts. This includes (but is not limited to) selectors, getters, setters, events, effects, ajax, plugins and UI library concepts.

In the next few posts, we will discuss the jQuery AJAX functions. There are 3 categories of questions: Explain the basic jQuery load() method; Explain the jQuery utility functions; and lastly, the king of all functions: Explain the jQuery ajax() function. In this post we will focus our attention on the load() function.

Basic load() method

The simplest AJAX method in jQuery is the load() method; given a URL, it will asynchronously load its contents and display it dynamically on the page (in the element specified).  In it’s simplest form, the load function looks something like this:

$('div').load('CurrentStatus.html');


A more complete example might be when you combine this functionality with a timer to update some element on a periodic basis.


// Load and display the current status every minute
setInterval(function() {
$("#currentStatus").load("CurrentStatus.html");
}, 60000);


The code above will get the entire contents of the specified web page. The load() function also allows you to get partial page content. The trick is to add a space to the URL and follow it with a jQuery selector. When the URL has loaded, the selector you specified will be used to select the portions of the loaded HTML to be displayed:


// Load the temperature section of the weather report
$('#db_status').load("CurrentStatus.html #DB");


The complete signature of the load() method takes in two additional optional parameters


.load( url, [ data ], [ complete(responseText, textStatus, XMLHttpRequest) ] )




url - A string containing the URL to which the request is sent.
data - A map or string that is sent to the server with the request.
complete(responseText, textStatus, XMLHttpRequest) - A callback function that is executed when the request completes.


Passing data to the load() method


If you pass in a string as the data, it is appended as a query string parameter. On the other hand, if you pass in an object, it is converted to name=value pairs. For example, the first call is passed as query string data and the second example shows an object that is passed to the call.


// Load the status for a particular server
$('#status').load("CurrentStatus.html", "server=db01");

// pass an object as data specifying an interval of day
$('#status').load("CurrentStatus.html",
{ server:'DB01', interval:'1day' });


Executing a callback function


The second optional parameter is a callback function that will execute on completion of the load() method.


$('#result').load('ajax/test.html', function() {
alert('Load was performed.');
});

One important fact to note is that the POST method is used if data is provided as an object; otherwise, GET is assumed.

50 comments:

  1. I really like what you have covered whole in your jquery series.
    thanks,
    H

    ReplyDelete
    Replies
    1. Hello Nikhil,

      What a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this.
      I'd like to share with you a OOP design question I have related to a group of classes/objects I'm developing in Java.
      I'm writing a little program to generate Cards for the Italian family game of Tombola (a sort of Bingo) and then use these cards to support the game when there are many players (tens or hundreds).
      Cards are made up by 15 numbers chosen among the set [1.90] and displaced on three rows with five numbers each.
      I’d like to have a “Card” class which objects represent playing Tombola card.
      Then I’ve an algorithm that arrange all the 90 numbers (they are in an int [90] array) so that is generate six cards at one time (six cards with no number in common are called a “series of cards”). It will make sense to avoid client program could create just one single card with a statement like:
      Card card1 = new Card();
      My question is related to the “factory pattern” to use for instantiating new Card objects and the place where to put the generation algorithm introduced above.
      Ensure sufficient information (accuracy, completeness, precision, and classification of the information, where warranted) is provided or display.
      Currently I’ve just a couple of ideas.
      The first:
      I use a public static method on the Card class that returns an array containing six cards.
      Very useful article, if I run into challenges along the way, I will share them here.

      Thanks,
      Kim

      Delete
  2. This is an excellent straight forward example and clearly presented explanation. Thank you.

    ReplyDelete
  3. Once you know what you want to see, then you can figure out where you want to stay.
    Situs Poker Online International resorts and hotels are common around the island and are great places to stay when you want easy beach access.

    For cheaper and more authentically Cuban accommodations,
    DominoQQ you can choose from all sorts of hotels and guest houses. Whether you stay in the capital of Havana, or decide to stop in some of the smaller towns, there is always going to be somewhere you can rent a room. Known as "casa particulares", there are small guest houses where people offer rooms for rent in their own homes. It's a common feature in Cuba and a way to same some money because the costs are usually quite low.

    These are basically all the details you need before you plan your Cuba voyage.BandarQ Once you have a travel plan worked out, all that's left is getting things booked and head out.

    Terri has traveled the world and is always looking forward to her next adventure.Domino 99 She prefers to visit new and exciting places instead of the usual destinations.

    ReplyDelete
  4. usually posts some incredibly exciting stuff like this. If youre new to this site :)
    That could be the finish of this report. Right here you will uncover some websites that we think youll value, just click the links.

    Agen Poker Online Indonesia Terbaik Terpercaya Terbesar 2017

    ReplyDelete
  5. An impressive share! I’ve just forwarded this onto a co-worker who
    has been conducting a little homework on this. And he actually bought me dinner
    because I stumbled upon it for him… lol. So allow me to reword this….
    Thank YOU for the meal!! But yeah, thanks for spending some
    time to discuss this subject here on your web page. Parabola Tv Muslim ::: Parabola Tv Muslim ::: Parabola Tv Muslim

    ReplyDelete
  6. growing muslim Entrepreneurship should be our motive. Who does wanna start business but are affraid of can take help from startup muslim. They have expertise and they also help people as well.

    ReplyDelete
  7. The blog or and best that is extremely useful to keep I can share the ideas of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
    animal jam | five nights at freddy's | hotmail login

    ReplyDelete

  8. Over time, in the sensual massage beautiful setting in Hawaii.
    Some of the best are a peacock feather or other light bird’s
    feather, silk scarf, wool muffler, cotton balls,
    cotton knit such as a soft tee shirt, dry natural sponge, marbles, tennis ball, leaves, flowers.
    Aromatherapy should also be of benefit for improving the function of the
    actual body organs.
    Jasa SEO Indonesia Murah Terbaik dan Profesional

    ReplyDelete


  9. The share your really gives us excitement. Thanks for your sharing. If you feel tired at work or study try to participate in our games to bring the most exciting feeling. Thank you!
    hotmail sign in | red ball | 192.168.1.1

    ReplyDelete
  10. Hi!How to callback ajax in jquery??

    ReplyDelete
  11. a pride for me to be able to discuss on a quality website because I just learned to make an article on
    cara menggugurkan kandungan

    ReplyDelete
  12. We find lots of learning after reading this very useful article . cara menggugurkan hamil

    ReplyDelete
  13. You can connect your HP wireless printer to Wi-Fi to printer from distance with the help of wireless feature. If you are a new user and do not know about the HP Wireless Printer Setup then get help from experts to set it up easily.

    ReplyDelete
  14. Aol desktop gold is very easy to use and it is all in one desktop. You can do multiple things on it. It provides the high-security feature to protect aol account from hackers. It automatically replaces your old version with the latest one. You don't have to do it. Download aol desktop gold from desktop gold

    ReplyDelete
  15. Geek squad is the best service provider. They help you to manage your device. To install or manage your device you can use their geek squad chat support feature. They find the best possible solution within minutes. You don't have to wait a lot for that. For further queries, you can visit geek squad best buy

    ReplyDelete
  16. It would not be wrong to state that Yahoo Support service is 24by7 ready to provide you feasible possible solutions to error code 400 at your disposal. Simply, by availing the above given troubleshooting service, one can have talk with customer care technicians and fetch the real time aid.

    Yahoo Help

    Yahoo Number

    ReplyDelete
  17. Are you one of those Epson printer users who are running into paper jamming problems? Are you not aware of the right troubleshooting process to resolve such kind of problems? Simply, you should remove the stuck paper from your printer and also check the paper tray alignment. Even if the same problem still arises, you should opt for the quick Epson error code 0xf3 directly from the professional geeks. So, why are you waiting for?

    ReplyDelete
  18. Hi, I am mason Lava. I am from The United State. I provide HP Laptop Support In worldwide. If you are an HP laptop user and your hp laptop touchpad not working.Get help from our Hp laptop experts. Our technician is available at any time anywhere

    ReplyDelete
  19. Have you really lost your Facebook account password? Don’t you know how to get it back without having to face any kind of problems ad hurdles regarding the same? Just be relaxed! You should approach the professionals who are proficient in providing the Facebook Customer Service and get the same.

    ReplyDelete
  20. Yahoo Customer Service: A Simple To Fix Technical Problem

    Do you want to do opt for the right kind of remedy and treatment to your problems pertaining to your Yahoo mail account? In such a case, you should take Yahoo Customer Service from a reliable source where you can have the quick problem solving solution, at the comfort of your home.
    https://www.customercare-email.net/yahoo-customer-service/

    ReplyDelete
  21. Can’t Find The Solution? Yahoo Phone Number Helps A Lot

    Are you unable to get the best in class solution to your problems pertaining to your Yahoo mail account? You should avail the right direct from the professionals who would comfortably assist you to have the quick yet effective solution to your problems by using Yahoo Phone Number at anytime.
    https://www.numbersfor-support.com/yahoo-customer-service-number/

    ReplyDelete
  22. To Cash Aap Transfer Failed Issues, Contact Cash Aap Customer Services
    If you have any issues while transfer money or bill through credit card, debit card or you are not able to access it anywhere on any device. So in that case, you can call our Cash App Customer Service at any time, they can resolve your issues easily. We are available anytime for any assistance.
    https://www.cashapphelps.net/cash-app-customer-service/

    ReplyDelete
  23. Top-Notch Technical Backing By Getting Yahoo Support Service
    If you have any kind of problems and hurdles, then you don’t need to approach all the customer support service providers. For the purpose of getting the right kind of customer care service, you should make use of Yahoo Support service and resolve your hitches and glitches in no time.
    https://www.callphonenumber.net/yahoo-support/

    ReplyDelete
  24. Take Cash App Support if you need quick help for problematic Cash Aap?
    Are you looking for a quick and effective solution to tackle problematic cache apps voluntarily? In such a case, you should connect with the Cash App Support team through various channels such as live chat, email support and live chat service. Doing this will help you in the best possible way.

    ReplyDelete
  25. Take Cash App Support if you need quick help for problematic Cash Aap?
    Are you looking for a quick and effective solution to tackle problematic cache apps voluntarily? In such a case, you should connect with the Cash App Support team through various channels such as live chat, email support and live chat service. Doing this will help you in the best possible way.
    https://www.cashapphelps.net/cash-app-support/

    ReplyDelete
  26. Obtain Yahoo Customer Service If Yahoo Account Get Hacked
    If you have any kind of technical problems pertaining to your hacked Yahoo account, you should make use of the Yahoo Customer Service which allows you to have a proper direction about the same. You should also get the proper technical backing from the professionals who will surely help you out.
    https://www.phonesupportnumbers.net/yahoo-customer-service/

    ReplyDelete
  27. Nice Post..
    24/7 help is available for HP solution center installation
    HP solution center is now known as a HP printer assistant. If you want to install it, you need to download it from HP support official website. It helps users to manage HP printer or scanner effectively. If you’re facing any technical issues with it, our technical support executives are much trained to apply the right technical instructions to install HP Solution Center in the right ways. Our techies are technically caring and capable, so they will finish this process within a few minutes. Our 24/7 help is open for you to get quick support or help.

    ReplyDelete
  28. While printing any document, you are experiencing canon printer in error state. This warning message can prevent you to work on your printing device. If you’re experiencing this error again and again, you should look for quality technical assistance. If you want to fix this error, you can give us a single call and our trained technicians are available round the clock to know your issue and its reasons. Our technical support experts have good knowledge of handling such types of issues within a few seconds. Our helpline number is open 24/7 to provide the solid solutions for any issue.

    ReplyDelete
  29. Quick Response From The Experts At Facebook Phone Number
    Are you having any kind of technical issues during the course of using Facebook? Do you also need the immediate

    help directly from the certified and adept technicians? For that, you should opt for the best way possible by just

    making use of the round the clock working Facebook Phone

    Number
    anytime.

    ReplyDelete
  30. Eliminate Blocking Problems By Just Using Facebook Phone Number
    At Facebook Phone Number, you

    will be able to get the reliable support to resolving blocking problems. Here, you will get to know about the

    various things pertaining to blocking and unblocking of your Facebook account user. Besides, if you face any issues

    regarding the same, you need to get the right aid from the professionals.

    ReplyDelete
  31. Expel Connections Errors At Once Through HP Support Assistant
    By moving toward HP Support Assistant, you will

    have the option to arrangement your printer to your PC or PC utilizing USB or remotely. You can have a word with

    these experts and request the assistance in regards to the associations and goals to such sort of issues in regards

    to the equivalent.

    ReplyDelete
  32. How Do I Get My Cash App Refund Back Without Any Mishaps?
    Do you not have money application account? On the off chance that indeed, you frequently utilize it to take into

    account different needs. If there should arise an occurrence of installment disappointment and you critically need

    Cash App Refund, you can get the correct sort

    of direction legitimately from the guaranteed experts at whenever from anyplace.

    ReplyDelete
  33. Get To Know About The Process To Get Facebook Forgot Password Recovered
    If you want to be aware of the process to get your Facebook Forgot Password recovered in a couple of seconds, you should make use of the

    troubleshooting professionals who are capable of directing the real time process in a step by step manner. So, why

    don’t you avail the right kind of help from the experts?

    ReplyDelete
  34. Get Facebook Forgot Password Back Using Alternative Mobile Number
    Facebook gives you the constant office to sort your secret phrase related issues and furthermore causes you to

    recoup Facebook Forgot Password with

    the guide of auxiliary email address. It causes you to check your character and furthermore encourages you to make

    new secret phrase for your Facebook account.

    ReplyDelete
  35. Is Hp Solution Center Capable Of Fixing Driver Update Problems?

    Yes, Hp Solution Center is capable of fixing the whole host of driver update and installation related problems at anytime from anywhere. In addition to this, you can also fetch the real time guidance and supervision regarding the performance of your printer with Hp Support.

    ReplyDelete

  36. How Do I Download Printer Drivers Easily With Epson Support Professionals?

    • Are you one of those who want to download Epson printer drivers?
    • Are you not aware of the process to get it downloaded from the genuine sources?
    For that, you should first of all avail Epson Support directly from the professionals who will surely help you out in a couple of seconds.

    ReplyDelete
  37. Set Up A Secured Password By Joining Yahoo Support Service

    Are you not aware of measures which would allow you to setup the secured password pertaining to your Yahoo mail account? Don’t need to worry! All you need is to make use of Yahoo Support Service and get the right kind of solution to your problems and hurdles in a couple of seconds.
    Read More:- https://www.googlehome-page.com/yahoo-customer-support-number/

    ReplyDelete

  38. Guidelines For Lost Password Recovery At How to fix yahoo account hacked issue

    Whenever you face any kind of problems regarding the lost password, you should make use of the correct and authentic troubleshooting guidance using the how to fix yahoo account hacked issue. It is absolutely free of cost troubleshooting aid provider which aids you round the clock. So, you will be able to get your password back in no time.Read More:- https://www.digitalworldsupport.com/social-media/how-to-fix-yahoo-account-hacked-issue/

    ReplyDelete
  39. How To Delete Old Emails On Gmail Using Gmail Number?

    If you can delete your older emails from your Google mail account, you should get to know the proper process to do so. Simply making proper use of Gmail Number and you will be able to have a word with the techies who will provide you with the right kind of solution to your problems comfortably.
    Read More:- https://www.dellsupportme.com/gmail-customer-support-number/

    ReplyDelete

  40. Gmail Customer Service: A Problematic Login Problem Solution
    Are you facing problems with the login into your Gmail account? Are you completely unable to get the right solution to your login problems? In such a case, you should make use of the right kind of guidance regarding the Gmail login. Simply, use Gmail Customer Service and get the aid quickly.

    ReplyDelete
  41. Approach HP Solution Center For Fixing Network Problems

    Yes, you are not only allowed to approach HP Solution Center but also fetch the instant technical backing directly from the professionals. If you want to avail the quickest remedy along with the supervision regarding the problems and hurdles, pertaining to HP printer network, you should get the free assistance at anytime.

    ReplyDelete
  42. Sort Paper Jamming Problems Using HP Printer support Anytime

    HP printer provides you the facility to fax, scan and print any kind of documents and images. In order to sort out paper jamming problems, you should make use of HP Printer Supportso that you can easily have a word with the right kind of technical backing and supervision directly from the professionals at anytime.

    ReplyDelete
  43. Want To Add Extra Security Of Your Gmail Account? Use Gmail Phone Number
    If you really want to add an extra layer of security over your Google mail account, you should quickly opt for the right guidance from the experts. Here, they will suggest you to enable different safety features and functions. For that, you should approach them using Gmail Phone Number

    ReplyDelete
  44. Take Assignment Help if you have any issue for composing your academic papers. If you connect with trustworthy service provider, browse various web pages of greatassignmenthelp for more information.
    Assignment Help Online
    Online Assignment Help
    Assignment Help Online Services
    Assignment Helper
    Assignment Assistance
    Assignment Help Experts
    Online Assignment Help Services

    ReplyDelete
  45. Being a student of USA, if you find tough to write your assignments, then select our Assignment Help USA services. With us, you will not get any issue in writing and content quality.
    Assignment Help Online
    Best Assignment Help
    Assignment Helper
    Assignment Help In USA
    Online Assignment Help
    Assignment Help Experts
    Online Assignment Help Services

    ReplyDelete
  46. How Can Novice Users Opt For Hp Assistant For Instant Guidance Of Experts?
    In order to opt for Hp Assistant, users are required to get in touch with the experts using different mediums such as live chat and email support service. With troubleshooting professionals, you can get share your problems and get the real time backing even in the odd hours.

    ReplyDelete
  47. Get Brother Support Service If Having Issues While Updating Drivers
    Are you not able to update the drivers of your Brother printer? For the same purpose, you should make use of the Brother Support t service. Here, you will get a chance to get in touch with the best in class technicians who are skilled and adept in providing you with the help regarding the same, with the ease.

    ReplyDelete
  48. You can use both online and desktop version of this software. If you face QuickBooks Error H505 then immediately contact certified experts to fix it. A team of certified experts is present round the clock to help customers regarding QuickBooks’s issues.

    ReplyDelete