It seems to me you're trying to make the calls be processed in
chronological order, or in other words: asynchronous...
You could try to set the asynchronous option to false, but I (and
many others) strongly advice you don't... I't might solve your
problem, but it also negates the benefits of using ajax.
Here goes:
new Ajax.Request(url, { ... }, false);
Greetz,
Wizz
On Nov 22, 9:12 pm, Rodrigo Carvajal <[EMAIL PROTECTED]>
wrote:
> // there's the original piece of code where i'm working...
>
> this.ajax_observer = this.refresh_options.bindAsEventListener(this);
>
> var current_time = new Date();
>
> timestamp = current_time.getTime();
>
> __ajax_options.onComplete = this.ajax_observer;
> __ajax_options.timestamp = timestamp;
> this.espected_timestamp=timestamp;
>
> this.ajax_request = new Ajax.Request(this.ajax_url,
> __ajax_options);
>
> there you see i done the binding of the handler function to the
> object, and the handler function and the request are part of "this"...
> BUT, i need to compare when the handler function is fired, if the
> timestamp asociated by the request who's fired te handler function...
> in this way... when i compare
> this.ajax_request.options.timestamp==this.espected_timestamp will
> return always true, because old request will be overwritten by the new
> requests pulled in the this.ajax_request object... in this way i would
> not compare the especific timestamp asociated with the especific
> request, because the ajax_request object is "disappeared" when i
> overwrite this.ajax_request... disapear to the sight but still fires
> the handler function ...
>
> i'm thinking that the only way is to return the timestamp from the
> server side ...
>
> On 22 nov, 15:04, "Richard Quadling" <[EMAIL PROTECTED]> wrote:
>
> > 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
-~----------~----~----~----~------~----~------~--~---