Side navigation
#3243 closed bug (invalid)
Opened August 11, 2008 12:08PM UTC
Closed August 13, 2008 03:33PM UTC
Last modified March 15, 2012 07:01PM UTC
jQuery.ajaxSetup({}) settings are overriden by jQuery.ajax
Reported by: | rene7705 | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.3 |
Component: | ajax | Version: | 1.2.3 |
Keywords: | ajaxSetup, override | Cc: | rene7705, flesler |
Blocked by: | Blocking: |
Description
Hi.
For my CMS, i want a statusbar that goes through the following stages:
1) Getting <url>
2) Processing <url>
3) Processed <url>
I want to achieve this by setting some global handlers for ajax events. I have tried using the global events, but they never got fired.
So at document-ready, i do this:
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){
if (mb.desktop.isAnAjaxActivityToReport(this)) {
mb.reportToEndUser("Processing " + this.url, true);
};
},
complete : function (xhr, ts) {
if (mb.desktop.isAnAjaxActivityToReport(this)) {
mb.reportToEndUser("Processed " + this.url, false);
};
}
});
But this wont work because local callbacks in jQuery.ajax() overrides any global callbacks with the same name made by jQuery.ajaxSetup()
I think it's also wise to fire global handlers Before local handlers. The global handler updates the status-bar, and the local handler does the actual work.
So I need the global handler to fire Before the local handler.
The simple solution is to change jquery-1.2.3.source.js around line 2781 to this:
function success(){
Fire the global callback
if (jQuery.ajaxSettings.success)
jQuery.ajaxSettings.success.call (s, 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] );
}
function complete(){
Fire the global callback
if (jQuery.ajaxSettings.complete)
jQuery.ajaxSettings.complete.call (s, xml, status);
Process result
if ( s.complete )
s.complete(xml, status);
The request was completed
if ( s.global )
jQuery.event.trigger( "ajaxComplete", [xml, s] );
// Handle the global AJAX counter
if ( s.global && ! --jQuery.active )
jQuery.event.trigger( "ajaxStop" );
}
I'd like to know if i'm on the right track here, and hope this solution can be incorporated in future jquery releases.
Please mail-CC rene7705@gmail.com if you have some kind of answer to this ticket.
Attachments (0)
Change History (11)
Changed August 11, 2008 03:00PM UTC by comment:1
cc: | → rene7705, flesler |
---|---|
milestone: | 1.2.3 → 1.3 |
need: | Review → Test Case |
Changed August 11, 2008 03:30PM UTC by comment:2
Global events are fired _after_ the local event finishes.
Wouldn't it make more sense to fire them before the local event is triggered?
Currently i dont use the global events. Please provide me with a correct example so i can hook those events.
Changed August 11, 2008 03:56PM UTC by comment:3
What do you consider global and local events ?
Changed August 11, 2008 03:57PM UTC by comment:4
global = set by jQuery("#something").ajaxSuccess
local = set in jQuery.ajax({})
according to the docs ;)
Changed August 11, 2008 04:32PM UTC by comment:5
Ok so...
In short, you don't have a problem with global events as you stated in the description, right ?
Just the order of local vs global events ?
Changed August 11, 2008 04:57PM UTC by comment:6
I can't get global events to work at all.
And the order of calls is significant, yes.
Changed August 11, 2008 05:22PM UTC by comment:7
>And the order of calls is significant, yes.
Ok.. if you think the order should be reversed, create a new feature ticket. Include a situation where the new order is clearly better than the actual one.
>I can't get global events to work at all.
This ticket will only handle the bug you mention.
You need to provide a test case where they don't work. If you simply don't know how to use them properly, then check the docs or ask on the google group.
Changed August 13, 2008 08:56AM UTC by comment:8
I do:
$('#mbStatusbar').ajaxSuccess(function(evt, request, settings){
alert (1);
$(this).html("<li>Successful Request!</li>");
});
and the event never fires.
i took this snippet straight from the docs.
I can't provide a test-url at the moment because it's located on a development server behind a firewall.
Changed August 13, 2008 08:57AM UTC by comment:9
note that #mbStatusbar does exist, i checked.
i refer to it case-sensitive.
Changed August 13, 2008 09:09AM UTC by comment:10
OK, my bad :-/
I was calling .ajaxSuccess before my page had initialized..
think i can get my statusbar to work with the event-structure as it is.
this ticket can be closed if you want; i realize that changing the .ajaxSetup structure might well result in broken apps for people who already use the existing structure.
Changed August 13, 2008 03:33PM UTC by comment:11
resolution: | → invalid |
---|---|
status: | new → closed |
Global events do work, the option 'global' is true by default.
About AjaxSetup... that's the expected behavior, the function sets the defaults for ajax requests.
Can you provide a test case where we can reproduce the initial problem with the global events ?