samogon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-09 23:32 UTC
prototype 1.5.0_rc1 Ajax.PeriodicalUpdater not working in IE
The following snippet of code does not work as expected in IE using
prototype 1.5.0_rc1
What should happen is that the "in onSuccess" alert should pop up
every
1.5 seconds.
What happens is that the "in onSuccess" alert pops up only once, at
page load.
<html>
<head>
<script src="/js/prototype.js"
type="text/javascript"></script>
<script type="text/javascript">
new Ajax.PeriodicalUpdater({}, ''/test.html'',
{
''decay'': 1, ''frequency'': 1.5,
''method'': ''get'',
''onSuccess'': onSuccess,
''onFailure'': onFailure
});
function onSuccess(req, json) {
alert("in onSuccess");
}
function onFailure(req) {
alert("in onFailure");
}
</script>
</head>
</html>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs
-~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2006-Oct-10 06:31 UTC
Re: prototype 1.5.0_rc1 Ajax.PeriodicalUpdater not working in IE
Hey there, samogon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a écrit :> The following snippet of code does not work as expected in IE using > prototype 1.5.0_rc1 > > What should happen is that the "in onSuccess" alert should pop up every > 1.5 seconds.No. You''re mistaken in your understanding. Ajax.PeriodicalUpdater''s interval and decay mechanism only governs the moments at which there is a check for *content update*. You will only get notified every time the content *changes*. So if you aim at a static-content file, only the first request will fire a notification. If you need periodical display w/o regard for change, just use window.setInterval and a regular Ajax.Updater call (and don''t forget to clear the interval on page unload). ''HTH -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Eric Harrison
2006-Oct-10 10:05 UTC
Re: prototype 1.5.0_rc1 Ajax.PeriodicalUpdater not working in IE
I am doing something similiar (to your example anyway) in which I was
trying to use Ajax.PeriodicalUpdater as a polling mechanism of sorts.
As explained by Christophe, Ajax.PeriodicalUpdater isn''t quite
designed to handle that sort of thing.
To get around this problem, I wrote my own simplistic wrapper to meet
my needs that I''m sure you could adapt for whatever situation you are
in. It borrows heavily from the concept of the PeriodicalUpdater, but
without actually using Ajax.Updater and performing various bits of js
logic according to the returns.
I''ve posted the relevant bits below:
Ajax.Poller = Class.create();
Ajax.Poller.prototype = Object.extend(new Ajax.Base(), {
initialize: function(container,url,options) {
this.setOptions(options);
this.onComplete = this.options.onComplete;
this.frequency = ( this.options.frequency || 1);
this.decay = ( this.options.decay > 1 ? this.options.decay : 2 );
this.updater = {};
this.container = container;
this.url = url;
this.start();
},
start: function() {
this.options.onComplete = this.updateComplete.bind(this);
this.onTimerEvent();
},
stop: function() {
this.updater.options.onComplete = undefined;
clearTimeout(this.timer);
(this.onComplete || Prototype.emptyFunction).apply(this,arguments);
},
updateComplete: function(request,json) {
// put some customized logic here (ie: this.onSuccess.apply(this,arguments); )
if ( request.responseText == this.lastText ) {
// no change
if ( this.options.decay) {
this.decay = this.decay * this.options.decay;
}
} else {
Element.update(this.container,request.responseText);
this.decay = this.options.decay || 1;
}
this.lastText = request.responseText;
this.timer = setTimeout(
this.onTimerEvent.bind(this),
this.decay * this.frequency * 1000
);
},
onTimerEvent: function() {
this.updater = new Ajax.Request(this.url,this.options);
}
});
Just place whatever logic you need in the updater. The only thing I
don''t like about this solution is the code redundancy and I''m
going to
look into fixing this more elegantly later, but for now this hack
works just fine.
Hopefully you''ll get inspiration from it to solve your problem.
-E
On 10/10/06, Christophe Porteneuve
<tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org>
wrote:>
> Hey there,
>
> samogon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a écrit :
> > The following snippet of code does not work as expected in IE using
> > prototype 1.5.0_rc1
> >
> > What should happen is that the "in onSuccess" alert should
pop up every
> > 1.5 seconds.
>
> No. You''re mistaken in your understanding.
Ajax.PeriodicalUpdater''s
> interval and decay mechanism only governs the moments at which there is
> a check for *content update*. You will only get notified every time the
> content *changes*. So if you aim at a static-content file, only the
> first request will fire a notification.
>
> If you need periodical display w/o regard for change, just use
> window.setInterval and a regular Ajax.Updater call (and don''t
forget to
> clear the interval on page unload).
>
> ''HTH
>
> --
> Christophe Porteneuve a.k.a. TDD
> "[They] did not know it was impossible, so they did it." --Mark
Twain
> Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org
>
> >
>
--
Eric Ryan Harrison, Developer
model13 Designs
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs
-~----------~----~----~----~------~----~------~--~---