Tom Fakes
2005-Dec-21 19:17 UTC
RE: Prototype: correct useage of onComplete withAjax.PeriodicalUpdater
>From a quick look at the source code, it looks like onComplete is onlycalled when the whole thing is done - in the case of Updater, right after the update, in the case of PeriodicalUpdater, right after it has been stopped. It looks like you need to pass your callback method as an ''insertion'' method in the options. This takes two parameters, the first will probably be the first parameter you passed to new PeriodicalUpdater, the second will be the response. e.g. new Ajax.PeriodicalUpdater(''buddies-and-locations'', ''/ajax-url'', { insertion: function (element, request){fooBar()}, onLoading: function(request){ showProgress()}, parameters: params, asynchronous:true, decay:2, frequency:20.0 }); -----Original Message----- From: Nicky Peeters [mailto:nicky.peeters-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org] Sent: Wednesday, December 21, 2005 7:13 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] Prototype: correct useage of onComplete withAjax.PeriodicalUpdater Hello all, I know it''s a Prototype question, but I hope someone can tell me what I''m doing wrong (I hope Prototype gets documented soon ;-( Problem: using a onComplete callback with Ajax.PeriodicalUpdater (using scriptaculous 1.5 with Prototype 1.4) Works: function fooBar() { Element.hide(''foobar''); } new Ajax.Updater(''buddies-and-locations'', ''/ajax-url'', { asynchronous:true, onComplete: function(request) {fooBar();}, onLoading: function(request) {showProgress();}, parameters: params }); Will not work when using a onComplete callback in the same manner : new Ajax.PeriodicalUpdater(''buddies-and-locations'', ''/ajax-url'', { onComplete: function (request){fooBar()}, onLoading: function(request){ showProgress()}, parameters: params, asynchronous:true, decay:2, frequency:20.0 }); But registering the onComplete using Ajax.Responders DOES work : Ajax.Responders.register({ onCreate: function() { if($(''buddies-loading-notice'') && Ajax.activeRequestCount>0) showProgress(); }, onComplete: function() { if($(''buddies-loading-notice'') && Ajax.activeRequestCount==0) fooBar(); } }); I tried passing the callback in various forms (return function()..., this.fooBar().bind(this) etc...) I worked around the problem using onSuccess in the PeriodicalUpdater (is that problematic?) Is it normal that onComplete callbacks do not work in the Ajax.PeriodicalUpdater ? Thanks alot, Nicky Peeters _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Nicky Peeters
2005-Dec-21 19:30 UTC
Re: Prototype: correct useage of onComplete withAjax.PeriodicalUpdater
Tom, Thanks for your reply, unfortunately I need to execute a function *after* the insertion of received content into the container, specifically to remove my progress-indication content. I could ofcourse write the insertion code myself, and add the other code in there, but since the onCompletes registered with Ajax.Responders work the removing of progress indication HTML should be better executed there. My current code works flawlessly using the onSuccess code to remove all progress indication HTML... I tried to throw a Venkman debugging sessions at the problem, but still fail to grasp how PeriodicalUpdater differs from Updater in respect to the dispatching of onComplete functions... Thx, Nicky On 21 Dec 2005, at 20:17, Tom Fakes wrote:>> From a quick look at the source code, it looks like onComplete is >> only > called when the whole thing is done - in the case of Updater, right > after the update, in the case of PeriodicalUpdater, right after it has > been stopped. > > It looks like you need to pass your callback method as an ''insertion'' > method in the options. This takes two parameters, the first will > probably be the first parameter you passed to new > PeriodicalUpdater, the > second will be the response. > > e.g. > > new Ajax.PeriodicalUpdater(''buddies-and-locations'', ''/ajax-url'', > { > insertion: function (element, request){fooBar()}, > onLoading: function(request){ showProgress()}, > parameters: params, > asynchronous:true, > decay:2, > frequency:20.0 > }); > > -----Original Message----- > From: Nicky Peeters [mailto:nicky.peeters-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org] > Sent: Wednesday, December 21, 2005 7:13 AM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails-spinoffs] Prototype: correct useage of onComplete > withAjax.PeriodicalUpdater > > Hello all, > > I know it''s a Prototype question, but I hope someone can tell me what > I''m doing wrong (I hope Prototype gets documented soon ;-( > > Problem: using a onComplete callback with Ajax.PeriodicalUpdater > (using scriptaculous 1.5 with Prototype 1.4) > > Works: > function fooBar() { > Element.hide(''foobar''); > } > > new Ajax.Updater(''buddies-and-locations'', ''/ajax-url'', > { asynchronous:true, > onComplete: function(request) {fooBar();}, > onLoading: function(request) {showProgress();}, > parameters: params > }); > > Will not work when using a onComplete callback in the same manner : > > new Ajax.PeriodicalUpdater(''buddies-and-locations'', ''/ajax-url'', > { > onComplete: function (request){fooBar()}, > onLoading: function(request){ showProgress()}, > parameters: params, > asynchronous:true, > decay:2, > frequency:20.0 > }); > > But registering the onComplete using Ajax.Responders DOES work : > > Ajax.Responders.register({ > onCreate: function() { > if($(''buddies-loading-notice'') && Ajax.activeRequestCount>0) > showProgress(); > }, > onComplete: function() { > if($(''buddies-loading-notice'') && Ajax.activeRequestCount==0) > fooBar(); > } > }); > > I tried passing the callback in various forms (return function()..., > this.fooBar().bind(this) etc...) > I worked around the problem using onSuccess in the PeriodicalUpdater > (is that problematic?) > > Is it normal that onComplete callbacks do not work in the > Ajax.PeriodicalUpdater ? > > Thanks alot, > > Nicky Peeters > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
Reasonably Related Threads
- RE: Prototype: correct useage of onCompletewithAjax.PeriodicalUpdater
- Prototype: correct useage of onComplete with Ajax.PeriodicalUpdater
- PeriodicalUpdater onComplete broken?
- Ajax.Request: onLoading executed after onComplete in IE
- Yet another periodicalupdater question