Chapter 12. Extending Ajax

 

This chapter covers

  • The jQuery Ajax framework
  • Adding Ajax prefilters
  • Adding Ajax transporters
  • Adding Ajax converters

Support for Ajax (Asynchronous JavaScript and XML) is one of the key features of jQuery, making it easy to request content from the server and to process the returned data and update the current page accordingly, without requiring a full refresh. You specify the URL to access, you can provide parameters to be sent along, and you can process the returned content in a callback function, as shown here:

$.ajax('product.php', {data: {prod_id: 'AB1234'},
    success: function(info) {...}});

jQuery also contains several convenience functions that encapsulate the Ajax abilities. For a simple request and response, you can use the get function, or to use an alternate parameter encoding, you use the post function. To load specific types of data, you can use the getScript or getJSON functions for JavaScript and JSON (JavaScript Object Notation) content respectively. If you want to place HTML content directly into an element on the page, you can use the load function on that element.

$.get('product.php', {prod_id: 'AB1234'}, function(info) {...});
$.getScript('product.js');
$('#mydiv').load('product.php', {prod_id: 'AB1234'}, function(info) {...});

jQuery offers additional abilities to set default values for all Ajax processing and to register handlers for events that occur during the Ajax lifecycle.

12.1. The Ajax framework

 
 
 

12.2. Adding an Ajax prefilter

 

12.3. Adding an Ajax transport

 

12.4. Adding an Ajax converter

 
 
 
 

12.5. Ajax plugins

 
 

12.6. Summary

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest