X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fajax%2Fajax.js;h=51457d0a733f72a13020c5c9a17978eef5f9ddc8;hb=3e165ae5ab080236eb0df35c691d6f3127c6499e;hp=cf6298d845096520ecf56d7e5941726dd478b457;hpb=2bdd208e4100f0b28b595b93eb07f18f63aa8ce5;p=jquery.git diff --git a/src/ajax/ajax.js b/src/ajax/ajax.js index cf6298d..51457d0 100644 --- a/src/ajax/ajax.js +++ b/src/ajax/ajax.js @@ -170,7 +170,10 @@ if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" ) /** * Attach a function to be executed whenever an AJAX request completes. * - * @example $("#msg").ajaxComplete(function(){ + * The XMLHttpRequest and settings used for that request are passed + * as arguments to the callback. + * + * @example $("#msg").ajaxComplete(function(request, settings){ * $(this).append("
  • Request Complete.
  • "); * }); * @desc Show a message when an AJAX request completes. @@ -185,7 +188,10 @@ if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" ) * Attach a function to be executed whenever an AJAX request completes * successfully. * - * @example $("#msg").ajaxSuccess(function(){ + * The XMLHttpRequest and settings used for that request are passed + * as arguments to the callback. + * + * @example $("#msg").ajaxSuccess(function(request, settings){ * $(this).append("
  • Successful Request!
  • "); * }); * @desc Show a message when an AJAX request completes successfully. @@ -199,8 +205,11 @@ if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" ) /** * Attach a function to be executed whenever an AJAX request fails. * - * @example $("#msg").ajaxError(function(){ - * $(this).append("
  • Error requesting page.
  • "); + * The XMLHttpRequest and settings used for that request are passed + * as arguments to the callback. + * + * @example $("#msg").ajaxError(function(request, settings){ + * $(this).append("
  • Error requesting page " + settings.url + "
  • "); * }); * @desc Show a message when an AJAX request fails. * @@ -209,9 +218,26 @@ if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" ) * @param Function callback The function to execute. * @cat AJAX */ + +/** + * Attach a function to be executed before an AJAX request is send. + * + * The XMLHttpRequest and settings used for that request are passed + * as arguments to the callback. + * + * @example $("#msg").ajaxSend(function(request, settings){ + * $(this).append("
  • Starting request at " + settings.url + "
  • "); + * }); + * @desc Show a message before an AJAX request is send. + * + * @name ajaxSend + * @type jQuery + * @param Function callback The function to execute. + * @cat AJAX + */ new function(){ - var e = "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess".split(","); + var e = "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","); for ( var i = 0; i < e.length; i++ ) new function(){ var o = e[i]; @@ -476,15 +502,15 @@ jQuery.extend({ * (String) contentType - When sending data to the server, use this content-type, * default is "application/x-www-form-urlencoded", which is fine for most cases. * - * (Boolean) processData - By default, data passed in as an object other as string - * will be processed and transformed into a query string, fitting to the default - * content-type "application/x-www-form-urlencoded". If you want to send DOMDocuments, - * set this option to false. + * (Boolean) processData - By default, data passed in to the data option as an object + * other as string will be processed and transformed into a query string, fitting to + * the default content-type "application/x-www-form-urlencoded". If you want to send + * DOMDocuments, set this option to false. * * (Boolean) async - By default, all requests are send asynchronous (set to true). * If you need synchronous requests, set this option to false. * - * (Function) before - A pre-callback to set custom headers etc., the + * (Function) beforeSend - A pre-callback to set custom headers etc., the * XMLHttpRequest is passed as the only argument. * * @example $.ajax({ @@ -525,7 +551,7 @@ jQuery.extend({ contentType: "application/x-www-form-urlencoded", processData: true, async: true, - before: null + beforeSend: null }, s); // if data available @@ -568,8 +594,10 @@ jQuery.extend({ xml.setRequestHeader("Connection", "close"); // Allow custom headers/mimetypes - if( s.before ) - s.before(xml); + if( s.beforeSend ) + s.beforeSend(xml); + if (s.global) + jQuery.event.trigger("ajaxSend", [xml, s]); // Wait for a response to come back var onreadystatechange = function(isTimeout){ @@ -600,7 +628,7 @@ jQuery.extend({ // Fire the global callback if( s.global ) - jQuery.event.trigger( "ajaxSuccess" ); + jQuery.event.trigger( "ajaxSuccess", [xml, s] ); // Otherwise, the request was not successful } else { @@ -609,12 +637,12 @@ jQuery.extend({ // Fire the global callback if( s.global ) - jQuery.event.trigger( "ajaxError" ); + jQuery.event.trigger( "ajaxError", [xml, s] ); } // The request was completed if( s.global ) - jQuery.event.trigger( "ajaxComplete" ); + jQuery.event.trigger( "ajaxComplete", [xml, s] ); // Handle the global AJAX counter if ( s.global && ! --jQuery.active )