Another related possibility, Terry, is that you could use Form.Element.Observer to check the value of a Form element periodically, then if the value changed (due to any update), it will trigger a callback that you define. For performance reasons, you probably want to be frugal about the number of polling pieces, but it's a related option to your general question, and is an option that is available in PrototypeJS lib:
Here's a link if you're interested: http://www.prototypejs.org/api/timedObserver new Form.Element.Observer( 'myelement', 0.2, // 200 milliseconds function(el, value){ alert('The form control has changed value to: ' + value) } ) On 6/9/07, Mark Holton <[EMAIL PROTECTED]> wrote: > > example code to explain in detail what I mean... Chris is certainly more > experienced than I, but this works, Terry.: > > <body id="partners" > > <input type="hidden" id="hdElem" value=""> > <div><input type="text" id='someFormElement' value="This will update > every 5 seconds" size="45"></div> > <div id='someElement' > style="height:70%;background-color:white;clear:left;">This will update every > 5 seconds</div> > > </body> > > <script type="text/javascript"> > new PeriodicalExecuter > ( > function(pe) > { > var url = "getValFromServer"; //server side file > var pars = "FORM.something=" + "hello"; //in case you > wanted to pass params > new Ajax.Request (url, { > method: 'post', > parameters: pars, > onSuccess: function(transport){ > var jsontimestr = > transport.responseText.evalJSON(true); > // store value in a hidden Form element: > if (jsontimestr.latestValFromServer == > $('hdElem').value) { > alert("values were the same"); > } else { > //update page > $('someFormElement').value = > jsontimestr.latestValFromServer; > $('hdElem').value = > jsontimestr.latestValFromServer; > $('someElement').innerHTML = > jsontimestr.latestValFromServer; > } > > } > }); > > }, > 5); // execute every 5 seconds > </script> > > ...would like to hear any thoughts. > cheers, > -Mark > > > On 6/9/07, Mark Holton <[EMAIL PROTECTED] > wrote: > > > > Ajax.PeriodicalUpdater does not extend from Ajax.Updater, so it does not > > support the evalJSON, and other methods, is that correct? So you are > > limited in someways, with respect to Ajax.Request > > > > Feel free to slap me around Chris (go easy though :) )... I'd try this > > by running a PeriodicalExecuter which called an Ajax.Request method. > > Then inside of the Ajax.Request parse the return JSON (or whatever > > return form you are using), place the value in the target DIV, and also > > place the value in a hidden Form element. Each call of Ajax.Request at > > the specified interval could then check the hidden Form value (last value > > updated), and you could perform your comparison with the new value, then > > complete whatever new DOM manipulation you intended if the val had changed. > > > > (never used lastText, lastResponseText, but that seems more elegant than > > placing it in a Form element. Is the above method violate any best > > practices? I'm trying to always pass JSON, and Ajax.PeriodicalUpdaterdoes > > not allow that as far as I read. Always would like to hear other > > options myself) > > > > cheers, > > Mark > > > > On 6/9/07, Christophe Porteneuve < [EMAIL PROTECTED]> wrote: > > > > > > > > > Hey, > > > > > > Terry Riegel a écrit : > > > > Using I am using the Ajax.PeriodicalUpdater, and it is working > > > great. > > > > How do I test to see if the content has changed from the last > > > request? > > > > > > Well, why do you need to? At any rate, it's a simple matter of saving > > > > > > the last responseText and comparing it to the new one. It does keep > > > it > > > in its lastText property, btw. > > > > > > -- > > > Christophe Porteneuve a.k.a. TDD > > > "[They] did not know it was impossible, so they did it." --Mark Twain > > > Email: [EMAIL PROTECTED] > > > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
