[jQuery] ajaxSetup callbacks
<div dir="ltr">I'm using jquery 1.2.3, and i've found a bit of a snafu in the ajax routines:
It seems that methods set by jQuery.ajaxSetup() are overridden by the options in jQuery.ajax()
This means that i cannot add a global handler to update a statusbar of what is being done when.
In short, i want my statusbar to go through these stages:
1) Getting <url>
2) Processing <url>
3) Processed <url>
if i do :
jQuery.ajaxSetup ({
type : "GET",
dataType : "html",
beforeSend : function (xhr) {
if (mb.desktop.isAnAjaxActivityToReport(this)) {
mb.reportToEndUser("Getting " + this.url, true);
};
if (typeof jsDump!='undefined') mb.reportToDebugger ('jQuery.ajax: about to send:\n'+jsDump.parse(this.dataPosted));
},
success : function (data, ts){
debugger;
if (mb.desktop.isAnAjaxActivityToReport(this)) {
mb.reportToEndUser("Processing " + this.url, true);
};
},
complete : function () {
if (mb.desktop.isAnAjaxActivityToReport(this)) {
mb.reportToEndUser("Received " + this.url, false);
};
}
});
it wont work because the jquery source for a success event is:
function success(){
// If a local callback was specified, fire it and pass it the data
if ( s.success )
s.success( data, status );
// Fire the global callback
if ( s.global )
jQuery.event.trigger( "ajaxSuccess", [xml, s] );
}
If i change this to:
function success(){
// Fire the global callback
if (jQuery.ajaxSettings.success) jQuery.ajaxSettings.success (data, status);
// If a local callback was specified, fire it and pass it the data
if ( s.success )
s.success( data, status );
// Fire the global callback
if ( s.global )
jQuery.event.trigger( "ajaxSuccess", [xml, s] );
}
then it will work.
But, i'd rather not mess with jQuery sources.
I've read the manual, and am aware of jQuery("#someElement").ajaxSuccess() but i haven't gotten it to work. The event doesnt fire, for a reason i can't figure out..
Help is much appreciated.
</div>