On 22/11/2007, Richard Quadling <[EMAIL PROTECTED]> wrote:
> I think I understand your request.
>
> The AJAX call back (onSuccess, onComplete) also need to be bound to this.
>
> BUT!!!!
>
> Make sure you have the Ajax request as a property of this ...
>
> Here is an edited example of a class which has a some methods to
> process things after an onComplete and also used within the class
> itself ...
>
> var classs_Alerter = Class.create({
>         initialize : function() {
>                 this.o_AJAX = new Ajax.PeriodicalUpdater('dot', 
> location.href, {
>                         frequency : 30,
>                         delay : 1,
>
>                         // Note binding of "this" - this relates to main 
> class, not
> Ajax.PeriodicalUpdater
>                         onException : (function(o_Transport, o_JSON) {
>                                 this.commonUpdate(this);
>                         }).bind(this),
>
>                         onFailure : (function(o_Transport, o_JSON) {
>                                 updateAjaxReport(o_Transport.statusText, 
> 'MAction_Failure_TH');
>                                 this.commonUpdate(this);
>                         }).bind(this),
>
>                         onSuccess : (function(o_Transport, o_JSON) {
>                                 if (!!o_JSON) {
>                                         $('Jobs').update(o_JSON.Jobs);
>                                         $('Chase').update(o_JSON.Chase);
>
>                                         if ('0 jobs' != o_JSON.Jobs) { 
> this.Play1.bind(this).delay(1); }
>                                         if ('0 jobs' != o_JSON.Chase) { 
> this.Play2.bind(this).delay(5); }
>                                 } else {
>                                         updateAjaxReport('<span 
> class="MErrors_SPAN">There us a problem
> with the server.<br />Please tell Richard.</span>',
> 'MAction_Failure_TH');
>                                 }
>
>                                 this.commonUpdate(this);
>                         }).bind(this)
>                 });
>
>                 this.commonUpdate(this);
>         },
>
>         Play1 : function() { 
> soundManager.play('mySound1','/global/tructyre.mp3'); },
>         Play2 : function() {
> soundManager.play('mySound2','/global/etarequireschasing.mp3'); },
>         commonUpdate : function(o_Alerter) {
>                 o_Alerter.o_Date = new Date();
>                 o_Alerter.o_NewDate = new Date(o_Alerter.o_Date.valueOf() + 
> (1000 *
> o_Alerter.o_AJAX.decay * o_Alerter.o_AJAX.frequency));
>                 $('Last').update(o_Alerter.o_Date.toLocaleString ());
>                 $('Next').update(o_Alerter.o_NewDate.toLocaleString ());
>         }
> });
>
> document.observe('dom:loaded', function(){o_Alterer = new classs_Alerter();});
>
>
>
> So, within the Ajax handlers you use this.o_AJAX to access the
> PeriodicalUpdater object.
>
> On 22/11/2007, Rodrigo Carvajal <[EMAIL PROTECTED]> wrote:
> >
> > maybe it doesn't understands so well; the issue is access de
> > ajax.request instance who fired the handler function, how this can be
> > done?...
> >
> > On 21 nov, 20:37, Rodrigo Carvajal <[EMAIL PROTECTED]>
> > wrote:
> > > i'm sending multiple ajax.request instances when i search for
> > > something when the 'keypress' event is fired; this is not a problem
> > > unless sometimes some ajax.request's don't came back in the same order
> > > that they was sended... in some cases earlier requests came back after
> > > late requests and that can be anoying to the user... i was thinking in
> > > atach to the request a timestamp and in the handler function wait for
> > > the last timestamp in the last request and dismiss the others; i don't
> > > know if there exists a more elegant way to do this...i was thinking to
> > > send the timestamp in the request and send it back from the server and
> > > check it that way but i would like to do in the client side only...
> > >
> > > example:
> > >
> > > $('textbox').observe('keypress', this.send_request.bind(this));
> > >
> > > ...
> > >
> > > this.send_request = function() {
> > >
> > > options.onComplete = this.ajax_handler; // Handler function for the
> > > request...
> > >
> > > var current_date = new Date();
> > >
> > > timestamp = current_date.getTime();
> > >
> > > options.timestamp=timestamp; // Timestamp in the Ajax options for
> > > identify it in the handler...
> > > this.expected_timestamp=timestamp;
> > >
> > > this.ajax_object = new Ajax.Request('sql.php', options); // Generate
> > > Request...
> > >
> > > }
> > >
> > > this.ajax_handler = function(response) {
> > >
> > > // Do anything i have to do here...
> > > // There i need to know the timestamp asociated by the ajax object
> > > that triggered this
> > > // function in order to use it only if is the last request and dismiss
> > > others
> > > // ....
> > >
> > > }
> > >
> > > thanks in advance for the help... ( and excuse my poor english ...)
> > > >
> >
>
>
> --
> -----
> Richard Quadling
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> "Standing on the shoulders of some very clever giants!"
>

Eek. A little complicated.

Maybe this is a better example ...

var a_class = Class.create({
 initialize : function() {

 this.o_AJAX = new Ajax.PeriodicalUpdater('dot', location.href, {

   onSuccess : (function(o_Transport, o_JSON) {
    this.commonUpdate();
   }).bind(this), // BIND calls.

  });

  this.commonUpdate();
 },

 commonUpdate : function() {
  // this.xxxx
 }
});


-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to