Using Global Event Handlers

$(document).ajaxStart(function(){   $("form").addClass("processing"); }); $(document).ajaxComplete(function(){   $("form").removeClass("processing"); });

jQuery provides methods to create global event handlers that are called on events such as initialization or completion for all AJAX requests. The global events are fired on each AJAX request. Table 13.2 lists the methods that can be used to register global event handlers.

An example of using a global event handler to set the class of a form is shown here:

$(document).ajaxStart(function(){   $("form").addClass("processing"); }); $(document).ajaxComplete(function(){   $("form").removeClass("processing"); ...

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.