I am trying to get a loader to display during ajax requests, but the "onCreate" is not getting triggered. The onComplete does. function loadComponent(section){ values = arguments[1] pars = $H(values).toQueryString() pars = "section="+section+"&"+pars var url = ''/internal/ajax/requests.php''; var ComponentLoader = new Ajax.Updater(''maincontent'', url, { asynchronous:true, onCreate: function() { loadingRequest(''mc_loader'', ''maincontent''); }, onComplete: function() { completedRequest(''mc_loader'', ''maincontent''); }, method: ''post'', parameters: pars, evalScripts: true }); } function loadingRequest(loader, target) { alert("request started"); new Effect.Appear($(loader), {duration: 0.5}); $(target).style.display = "none"; } function completedRequest(loader, target) { alert("request Done"); new Effect.Fade($(loader), {duration: 0.5}); new Effect.BlindDown($(target)); } Can any one see what I am doing wrong? ______________________________________________________________________ Alex Duffield . Principal . InControl Solutions . http:// www.incontrolsolutions.com _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
It seems like onCreate only gets called like so in prototype: Ajax.Responders.dispatch(''onCreate'', this, this.transport); In other words, only the global responders will get it. I''m with you though in wanting a reliable onCreate to happen before looking at the readystate events. I''ve been using onLoading for awhile, but I''m testing right now with a local webserver and can actually reproduce the race condition whereby onLoading gets triggered after onComplete by sticking console.debug( event) on line 765 of prototype.js. What is anyone else doing? I''m thinking of just adding a similar line of code for onCreate like onComplete so that the instance of the AjaxRequest can name it''s own onCreate and the responders will still get called. But I''d of course rather not edit prototype.js. -l Alex Duffield in message [Rails-spinoffs] onCreate not getting triggered. (Fri, 06/16 10:32):> I am trying to get a loader to display during ajax requests, but the > "onCreate" is not getting triggered. The onComplete does. > > > function loadComponent(section){ > values = arguments[1] > pars = $H(values).toQueryString() > pars = "section="+section+"&"+pars > var url = ''/internal/ajax/requests.php''; > > var ComponentLoader = new Ajax.Updater(''maincontent'', url, { > asynchronous:true, > onCreate: function() { loadingRequest(''mc_loader'', > ''maincontent''); }, > onComplete: function() { > completedRequest(''mc_loader'', ''maincontent''); }, > method: ''post'', > parameters: pars, > evalScripts: true }); > } > > function loadingRequest(loader, target) > { > alert("request started"); > new Effect.Appear($(loader), {duration: 0.5}); > $(target).style.display = "none"; > } > > function completedRequest(loader, target) > { > alert("request Done"); > new Effect.Fade($(loader), {duration: 0.5}); > new Effect.BlindDown($(target)); > } > > Can any one see what I am doing wrong? > > ______________________________________________________________________ > Alex Duffield . Principal . InControl Solutions . http:// > www.incontrolsolutions.com > > >> _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs-- Lindsey Simon lsimon-kAMMLXQ8Af9Wk0Htik3J/w@public.gmane.org Key fingerprint = C6A9 B9D9 677E A631 3E7F 43BF 5E2F 77F1 A33C B117 Public Key: http://www.commoner.com/pubkey.asc
OK, figured it out, so Ill answer my own question in case it is use full for some one else. There is no "onCreate" during ajax calls. Only onLoading, onLoaded, onInteractive, or onComplete. so I changed the OnCreate line to: onLoading: function() { loadingRequest(''mc_loader'', ''maincontent''); }, And we are now working. :) ______________________________________________________________________ Alex Duffield . Principal . InControl Solutions . http:// www.incontrolsolutions.com On 16-Jun-06, at 10:32 AM, Alex Duffield wrote:> I am trying to get a loader to display during ajax requests, but > the "onCreate" is not getting triggered. The onComplete does. > > > function loadComponent(section){ > values = arguments[1] > pars = $H(values).toQueryString() > pars = "section="+section+"&"+pars > var url = ''/internal/ajax/requests.php''; > > var ComponentLoader = new Ajax.Updater(''maincontent'', url, { > asynchronous:true, > onCreate: function() { loadingRequest(''mc_loader'', > ''maincontent''); }, > onComplete: function() { completedRequest(''mc_loader'', > ''maincontent''); }, > method: ''post'', > parameters: pars, > evalScripts: true }); > } > > function loadingRequest(loader, target) > { > alert("request started"); > new Effect.Appear($(loader), {duration: 0.5}); > $(target).style.display = "none"; > } > > function completedRequest(loader, target) > { > alert("request Done"); > new Effect.Fade($(loader), {duration: 0.5}); > new Effect.BlindDown($(target)); > } > > Can any one see what I am doing wrong? > > ______________________________________________________________________ > Alex Duffield . Principal . InControl Solutions . http:// > www.incontrolsolutions.com > > > > _______________________________________________ > 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
Ya ended up going with onLoading as well. At least for now. Now my problem is that my server/application is to fast!! (go figure) I am displaying my "loading" graphic to the user on the "onLoading" and then hiding it on "onComplete" but the thing just flashes for les than a second and is all but useless. Has any one come up with a good solution to only show the loader if the request is taking more than X seconds or something?? Thanks. ______________________________________________________________________ Alex Duffield . Principal . InControl Solutions . http:// www.incontrolsolutions.com On 16-Jun-06, at 12:13 PM, Lindsey Simon wrote:> It seems like onCreate only gets called like so in prototype: > Ajax.Responders.dispatch(''onCreate'', this, this.transport); > > In other words, only the global responders will get it. > > I''m with you though in wanting a reliable onCreate to happen before > looking at the readystate events. > > I''ve been using onLoading for awhile, but I''m testing right now with a > local webserver and can actually reproduce the race condition whereby > onLoading gets triggered after onComplete by sticking console.debug( > event) on line 765 of prototype.js. > > What is anyone else doing? I''m thinking of just adding a similar > line of > code for onCreate like onComplete so that the instance of the > AjaxRequest can name it''s own onCreate and the responders will > still get > called. But I''d of course rather not edit prototype.js. > -l > > Alex Duffield in message [Rails-spinoffs] onCreate not getting > triggered. (Fri, 06/16 10:32): > >> I am trying to get a loader to display during ajax requests, but the >> "onCreate" is not getting triggered. The onComplete does. >> >> >> function loadComponent(section){ >> values = arguments[1] >> pars = $H(values).toQueryString() >> pars = "section="+section+"&"+pars >> var url = ''/internal/ajax/requests.php''; >> >> var ComponentLoader = new Ajax.Updater(''maincontent'', url, { >> asynchronous:true, >> onCreate: function() { loadingRequest(''mc_loader'', >> ''maincontent''); }, >> onComplete: function() { >> completedRequest(''mc_loader'', ''maincontent''); }, >> method: ''post'', >> parameters: pars, >> evalScripts: true }); >> } >> >> function loadingRequest(loader, target) >> { >> alert("request started"); >> new Effect.Appear($(loader), {duration: 0.5}); >> $(target).style.display = "none"; >> } >> >> function completedRequest(loader, target) >> { >> alert("request Done"); >> new Effect.Fade($(loader), {duration: 0.5}); >> new Effect.BlindDown($(target)); >> } >> >> Can any one see what I am doing wrong? >> >> _____________________________________________________________________ >> _ >> Alex Duffield . Principal . InControl Solutions . http:// >> www.incontrolsolutions.com >> >> >> > >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > -- > > Lindsey Simon > lsimon-kAMMLXQ8Af9Wk0Htik3J/w@public.gmane.org > Key fingerprint = C6A9 B9D9 677E A631 3E7F 43BF 5E2F 77F1 A33C B117 > Public Key: http://www.commoner.com/pubkey.asc > _______________________________________________ > 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