TAILIEUCHUNG - JQuery: Novice to Ninja- P16

JQuery: Novice to Ninja- P16:No matter what kind of ninja you are—a cooking ninja, a corporate lawyer ninja, or an actual ninja ninja—virtuosity lies in first mastering the basic tools of the trade. Once conquered, it’s then up to the full-fledged ninja to apply that knowledge in creative and inventive ways. | 202 jQuery Novice to Ninja The search results are returned in the form of an object containing a results array. We iterate over each of the array items using jQuery s .each helper method. This function will execute the function we pass to it once for each item in the initial array. For each item we create a new div containing the user s profile picture a link to their profile on Twitter and the text of the celebrity-related tweet. The result a cool Twitter display in just a few lines of code Working with JSON If you ve tried a few getJSON calls to remote servers you might have noticed that the data returned requires a bit of work to decipher. You ll mostly have to figure it out for yourself. Different services have API documentation of varying quality and clarity. Sometimes it will provide you with examples but at other times you ll be left on your own. One way to examine an API s data structure is to type the API URL directly into your web browser and inspect the resulting JSON directly. The jQuery Ajax Workhorse If you were feeling particularly adventurous and hunted down the load function in the jQuery core library source code you d find that sitting snuggly at the bottom of the function would be a call to the .ajax method. In fact if you were to investigate any of jQuery s Ajax functions you d find it s the same with all of them All of jQuery s Ajax functions are simply wrappers around the .ajax method each designed to provide you with a simple interface for a specific type of task. By having these helper methods and additional functionality jQuery gives you an Ajax Swiss Army knife that strikes the perfect balance between power and ease-of-use. The .ajax method is the heart of jQuery s Ajax abilities and is the most powerful and customizable Ajax method available to us. Being the most complex in jQuery s arsenal it can take a while to conquer but it s well worth the effort this is the creature you ll be spending most of your Ajax time with. Construction Ajax .