I''ve been trying to use the prototype.js Ajax obect''s event
handlers (onCreate, onComplete) inside the options tags as
below:
function updateCalendar(today, id){
new Ajax.Updater("calendars", "calendar.inc.php",
{asynchronous: true,
onCreate: function(){ showBusy },
onComplete: function(){ hideBusy },
method: "get",
parameters: "today=" + today +"&hotel_id=" +
"<?=$_SESSION[hotel_id]?>"
});
}
function showBusy(){
new
Effect.Appear(''busy'',{duration:0.5,queue:''end''});
}
function hideBusy(){
new
Effect.Fade(''busy'',{duration:0.5,queue:''end''});
}
No matter how I try however these event handlers do not work. Any suggestions as
to what I am doing wrong? I am using
prototype 1.5.0_rc0 btw.
Regards,
Owen
I belive you will want to add the () to the showBusy and hideBusy call like
so:
...
onCreate: function(){showBusy();},
onComplete: function(){hideBusy()},
...
but I would think that you should just be able to omit the anonymous
function all-together like so:
...
onCreate: showBusy,
onComplete: hideBusy,
...
When you do this you don''t want the () as you are just passing the name
instead of calling the function as with the anonymous function.
Brandon
On 6/26/06, Owen Franssen
<owen-fHxLqwHf0PytTk9+fKAAsaxOck334EZe@public.gmane.org>
wrote:>
> I''ve been trying to use the prototype.js Ajax obect''s
event handlers
> (onCreate, onComplete) inside the options tags as
> below:
>
> function updateCalendar(today, id){
> new Ajax.Updater("calendars", "calendar.inc.php",
> {asynchronous: true,
> onCreate: function(){ showBusy },
> onComplete: function(){ hideBusy },
> method: "get",
> parameters: "today=" + today +"&hotel_id=" +
> "<?=$_SESSION[hotel_id]?>"
> });
> }
>
> function showBusy(){
> new
Effect.Appear(''busy'',{duration:0.5,queue:''end''});
> }
>
> function hideBusy(){
> new
Effect.Fade(''busy'',{duration:0.5,queue:''end''});
> }
>
> No matter how I try however these event handlers do not work. Any
> suggestions as to what I am doing wrong? I am using
> prototype 1.5.0_rc0 btw.
>
> Regards,
> Owen
>
>
> _______________________________________________
> 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
function updateCalendar(today, id){
new Ajax.Updater("calendars", "calendar.inc.php",
{asynchronous: true,
onCreate: function(){ showBusy },
onComplete: function(){ hideBusy },
method: "get",
parameters: "today=" + today +"&hotel_id=" +
"<?=$_SESSION[hotel_id]?>"
});
}
It doesn''t take long to pull a request. Maybe the hide event occurs
before
the show event has a chance to display? Did you try to breakpoint (or
alert();) these handlers ?
If you want to show an activity icon, there''s also a "global"
way of doing
this:
// Show Ajax progress indicator
var myGlobalHandlers = {
onCreate: function() {
$(''ajaxworking'').style.visibility =
''visible'';
},
onComplete: function() {
$(''ajaxworking'').style.visibility =
''hidden'';
}
};
Ajax.Responders.register(myGlobalHandlers); // Register
the handlers for content update
And if you need a spinner...
http://www.napyfab.com/ajax-indicators/
The only comment I have on the code you''ve written, is sometimes I need
to
.bind(this) to the event handlers: e.g., OnComplete: showBusy()... Oops,
there''s the problem. You didn''t include parens to invoke your
handler.
Sam