Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 16. jQuery, Ajax, Data Formats: ... > Using Ajax on Your Whole Site

16.3. Using Ajax on Your Whole Site

16.3.1. Problem

You have a large web application with Ajax calls occurring throughout the code base and need to define default settings for all requests throughout the application.

16.3.2. Solution

(function($) {
    $(document).ready(function() {
        $('#loadingIndicator')
            .bind('ajaxStart', function() {
                $(this).show();
            })
            .bind('ajaxComplete', function() {
                $(this).hide();
            });
        $.ajaxSetup({
            cache: true,
            dataType: 'json',
            error: function(xhr, status, error) {
                alert('An error occurred: ' + error);
            },
           timeout: 60000, // Timeout of 60 seconds
            type: 'POST',
            url: 'ajax-gateway.php'
        }); // Close $.ajaxSetup()
    }); // Close .read()
})(jQuery);


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint