[jQuery] Global AJAX handlers

2006-09-24 Thread Jörn Zaefferer
Hi folks,

which of the following examples of global ajax handlers make more sense 
and are easier to understand?

$("#msg").ajaxSuccess(function(){
  $(this).append("Successful Request!");
});

or

$.ajaxSuccess(function(){
  $("#msg").append("Successful Request!");
});

With chaining:
$("#msg").ajaxStart(function(){
  $(this).show();
}).ajaxStop(function() {
 $(this).hide();
});

or

var msg = $('#msg');
$.ajaxStart(function() {
  msg.show();
});
$.ajaxStop(function() {
  msg.hide();
});

Your opinion is appreciated.

-- Jörn

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Global AJAX handlers

2006-09-24 Thread Klaus Hartl


Jörn Zaefferer schrieb:
> Hi folks,
> 
> which of the following examples of global ajax handlers make more sense 
> and are easier to understand?
> 
> $("#msg").ajaxSuccess(function(){
>   $(this).append("Successful Request!");
> });
> 
> or
> 
> $.ajaxSuccess(function(){
>   $("#msg").append("Successful Request!");
> });
> 
> With chaining:
> $("#msg").ajaxStart(function(){
>   $(this).show();
> }).ajaxStop(function() {
>  $(this).hide();
> });
> 
> or
> 
> var msg = $('#msg');
> $.ajaxStart(function() {
>   msg.show();
> });
> $.ajaxStop(function() {
>   msg.hide();
> });
> 
> Your opinion is appreciated.
> 
> -- Jörn



Hi Jörn,

I like chaining most!

Although I think the following might make more sense anyway:

$.ajax({
...
stop: function() {},
start: function() {},
...
});

That way I have more control over which XHR requests are displayed. 
There may be some that the user is not aware of and does not need to be 
(validation, ping etc.)


-- Klaus

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Global AJAX handlers

2006-09-24 Thread Brandon Aaron
Well I think global should probably mean global and not attached to
anything but the jQuery object. Perhaps sometimes I don't want or need
to have an ajaxSuccess method be attached to a DOM node. The only way
I think having it like this:
$('#msg').ajaxStart(...
makes sense is if mutliple global handlers can be attached.

Brandon

On 9/24/06, Jörn Zaefferer <[EMAIL PROTECTED]> wrote:
> Hi folks,
>
> which of the following examples of global ajax handlers make more sense
> and are easier to understand?
>
> $("#msg").ajaxSuccess(function(){
>   $(this).append("Successful Request!");
> });
>
> or
>
> $.ajaxSuccess(function(){
>   $("#msg").append("Successful Request!");
> });
>
> With chaining:
> $("#msg").ajaxStart(function(){
>   $(this).show();
> }).ajaxStop(function() {
>  $(this).hide();
> });
>
> or
>
> var msg = $('#msg');
> $.ajaxStart(function() {
>   msg.show();
> });
> $.ajaxStop(function() {
>   msg.hide();
> });
>
> Your opinion is appreciated.
>
> -- Jörn
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Global AJAX handlers

2006-09-24 Thread Andre Lewis
I think the global responders should be attached to the jQuery object rather than to a DOM element. That said, it's very useful to be able to override the global responders for individual requests -- as Klaus points out, there are often XHR requests that don't merit the user's attention.
AndreOn 9/24/06, Klaus Hartl <[EMAIL PROTECTED]> wrote:
Jörn Zaefferer schrieb:> Hi folks,>> which of the following examples of global ajax handlers make more sense> and are easier to understand?>> $("#msg").ajaxSuccess(function(){
>   $(this).append("Successful Request!");> });>> or>> $.ajaxSuccess(function(){>   $("#msg").append("Successful Request!");
> });>> With chaining:> $("#msg").ajaxStart(function(){>   $(this).show();> }).ajaxStop(function() {>  $(this).hide();> });>> or>> var msg = $('#msg');
> $.ajaxStart(function() {>   msg.show();> });> $.ajaxStop(function() {>   msg.hide();> });>> Your opinion is appreciated.>> -- Jörn

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Global AJAX handlers

2006-09-24 Thread Mike Alsup
> the global responders for individual requests -- as Klaus points out, there
> are often XHR requests that don't merit the user's attention.

You can't really "override" the global responders.  If you declare
local handlers they are called in addition to the global methods, not
instead of them.

Mike

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Global AJAX handlers

2006-09-25 Thread Andre Lewis
On 9/24/06, Mike Alsup <[EMAIL PROTECTED]> wrote:
> the global responders for individual requests -- as Klaus points out, there> are often XHR requests that don't merit the user's attention.You can't really "override" the global responders.  If you declare
local handlers they are called in addition to the global methods, notinstead of them.MikeMike, I agree, right now there is no override mechanism. It would be pretty easy to add one though -- add an optional boolean argument (supressGlobalResponders or something) on the ajax function, and then check its value before invoking the global responders. You could then utilize a global responder for the common case (when the user needs feedback), but override the globals when the user doesn't need to be aware of the activity.

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Global AJAX handlers

2006-09-25 Thread Jörn Zaefferer
> Mike, I agree, right now there is no override mechanism. It would be
> pretty
> easy to add one though -- add an optional boolean argument
> (supressGlobalResponders or something) on the ajax function, and then
> check
> its value before invoking the global responders. You could then utilize a
> global responder for the common case (when the user needs feedback), but
> override the globals when the user doesn't need to be aware of the
> activity.

How about a "global" option for a ajax request? If true, global handlers are 
called, if false, they are not. Starting from the current behaviour, the 
default would be true.

-- Jörn
-- 
NEU: GMX DSL Sofort-Start-Set - blitzschnell ins Internet!
Echte DSL-Flatrate ab 0,- Euro* http://www.gmx.net/de/go/dsl

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Global AJAX handlers

2006-09-25 Thread Mike Alsup
Andre, Zörn,

Those are both good ideas for overriding the global callbacks.  I'd
like that capability.

Mike

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/