[Proto-Scripty] Re: Periodical Updater detect content change
2009/6/24 Aamchi aman.ra...@googlemail.com: Hi Richard, Your example works perfectly :-) Just a few minor things that I had to change to make it actually work (not being fussy, just if someone else finds this useful as well and wants to try it out): -The this operator didn't work for me, I replaced it with o_Updater - In the PHP the array key which stores the hash is 'Hash' and not 'thisHash', so replace thisHash with Hash in the js-code - And when updating hash: o_Updater.options.lastHash = o_JSON.thisHash (instead of o_Updater.options.lastHash != o_JSON.thisHash) Thanks again. Aman On 24 Jun., 12:12, Richard Quadling rquadl...@googlemail.com wrote: 2009/6/23 Aamchi aman.ra...@googlemail.com: Thanks, for your response. I'm not 100% sure if I understand correctly what you mean. If I get some data and generate a hash and write this to the JSON header and retrieve this when calling onSuccess, how will I still have the previous hash? From where will I get this? Won't the updated data cause the hash to be overwritten in the JSON header? Or do I have to send two hashes always and compare them? On 23 Jun., 22:57, Richard Quadling rquadl...@googlemail.com wrote: 2009/6/23 Aamchi aman.ra...@googlemail.com Hi, I was wondering if Ajax.PeriodicalUpdater can detect if content has changed since the last update and if so trigger an event. So for example I have a scoreboard which fetches data every 5 seconds and displays this. I would be cool if there could be some kind of notification if content had changed. I know that the new content is stores in responseText but how can I compare it to the previous content... Thanks, Aman Personally, I would do this server side. Assuming you get the data in some sort of structure before either rending some HTML and sending it or just sending it JSON'd, then you should be able to build a hash of the data. See [1] for info on Hash Functions. So. If you sent the hash value in a X-JSON header along with an onSuccess() callback, you can extract the hash from the second param to the onSuccess and compare this with the previously retrieved hash to indicate you've got changed data. See [2] for details about PeriodicalUpdater update notification and [3] for the parameters to common callbacks. Regards, Richard. [1]http://en.wikipedia.org/wiki/Hash_function [2]http://www.prototypejs.org/api/ajax/periodicalUpdater http://www.prototypejs.org/api/ajax/periodicalUpdater[3]http://www.prototypejs.org/api/ajax/options http://www.prototypejs.org/api/ajax/options -- - Richard Quadling Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! You add a previousHash:null; to your periodic updater and check that value against the one coming in via the X-JSON header. If it is different, then the data is different. If it is the same, then the data is the same. Either way, once evaluated, same the new hash. Untested (sorry), but adapting the example at [1] ... var o_Updater = new Ajax.PeriodicalUpdater ( 'lastLogin', '/lastLogin.php', { method : 'get', frequency : 3, decay : 2, lastHash : null, onSuccess : function(o_Transport, o_JSON) { // Do we have JSON? if (!!o_JSON) { // Do we have a previous hash? if (!!this.options.lastHash (this.options.lastHash != o_JSON.thisHash)) { // Hashes are different. Maybe activate an effect to show the highlighted data and slowly fade away over time. } // Update hash. this.options.lastHash != o_JSON.thisHash; } } } ); The code on the server would be something like this (I'm using PHP). ?php // Assume we are getting this data from a database. $a_Data = array ( 'Name' = 'Richard Quadling', 'LastPost' = '2009-06-24 10:00:00', ); // Build hash $s_Hash = array('Hash' = md5(serialize($a_Data))); // Generate output. $s_Output = tbodytrtd{$a_Data['Name']}/tdtd{$a_Data['LastPost']}/td/tbody; // X-JSON Header header('X-JSON: ' . json_encode($s_Hash, JSON_FORCE_OBJECT)); // Output results. echo $s_Output; ? The PHP outputs (edited) ... X-JSON: {Hash:a0c23e7f9651f2b65135932917b7f03a} Content-type: text/html tbodytrtdRichard Quadling/tdtd2009-06-24 10:00:00/td/tbody So the X-JSON header is presented as o_JSON in
[Proto-Scripty] Re: Periodical Updater detect content change
There is also a Form.observer http://www.prototypejs.org/api/timedObserver/form-observer I used to use this but implemented my own version of it with a cache and some hashing, it didnt take long to write and works perfectly HTH Alex - Original Message - From: Aamchi aman.ra...@googlemail.com To: Prototype script.aculo.us prototype-scriptaculous@googlegroups.com Sent: Tuesday, June 23, 2009 11:19 PM Subject: [Proto-Scripty] Re: Periodical Updater detect content change Thanks, for your response. I'm not 100% sure if I understand correctly what you mean. If I get some data and generate a hash and write this to the JSON header and retrieve this when calling onSuccess, how will I still have the previous hash? From where will I get this? Won't the updated data cause the hash to be overwritten in the JSON header? Or do I have to send two hashes always and compare them? On 23 Jun., 22:57, Richard Quadling rquadl...@googlemail.com wrote: 2009/6/23 Aamchi aman.ra...@googlemail.com Hi, I was wondering if Ajax.PeriodicalUpdater can detect if content has changed since the last update and if so trigger an event. So for example I have a scoreboard which fetches data every 5 seconds and displays this. I would be cool if there could be some kind of notification if content had changed. I know that the new content is stores in responseText but how can I compare it to the previous content... Thanks, Aman Personally, I would do this server side. Assuming you get the data in some sort of structure before either rending some HTML and sending it or just sending it JSON'd, then you should be able to build a hash of the data. See [1] for info on Hash Functions. So. If you sent the hash value in a X-JSON header along with an onSuccess() callback, you can extract the hash from the second param to the onSuccess and compare this with the previously retrieved hash to indicate you've got changed data. See [2] for details about PeriodicalUpdater update notification and [3] for the parameters to common callbacks. Regards, Richard. [1]http://en.wikipedia.org/wiki/Hash_function [2]http://www.prototypejs.org/api/ajax/periodicalUpdater http://www.prototypejs.org/api/ajax/periodicalUpdater[3]http://www.prototypejs.org/api/ajax/options http://www.prototypejs.org/api/ajax/options -- - Richard Quadling Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Periodical Updater detect content change
I thought of that too. But this only works in forms doesn't it? How do I detect a changed within a div which is reloaded every few seconds? Would you mind sending me an example? Thanks, Aman On 24 Jun., 08:36, Alex McAuley webmas...@thecarmarketplace.com wrote: There is also a Form.observerhttp://www.prototypejs.org/api/timedObserver/form-observer I used to use this but implemented my own version of it with a cache and some hashing, it didnt take long to write and works perfectly HTH Alex - Original Message - From: Aamchi aman.ra...@googlemail.com To: Prototype script.aculo.us prototype-scriptaculous@googlegroups.com Sent: Tuesday, June 23, 2009 11:19 PM Subject: [Proto-Scripty] Re: Periodical Updater detect content change Thanks, for your response. I'm not 100% sure if I understand correctly what you mean. If I get some data and generate a hash and write this to the JSON header and retrieve this when calling onSuccess, how will I still have the previous hash? From where will I get this? Won't the updated data cause the hash to be overwritten in the JSON header? Or do I have to send two hashes always and compare them? On 23 Jun., 22:57, Richard Quadling rquadl...@googlemail.com wrote: 2009/6/23 Aamchi aman.ra...@googlemail.com Hi, I was wondering if Ajax.PeriodicalUpdater can detect if content has changed since the last update and if so trigger an event. So for example I have a scoreboard which fetches data every 5 seconds and displays this. I would be cool if there could be some kind of notification if content had changed. I know that the new content is stores in responseText but how can I compare it to the previous content... Thanks, Aman Personally, I would do this server side. Assuming you get the data in some sort of structure before either rending some HTML and sending it or just sending it JSON'd, then you should be able to build a hash of the data. See [1] for info on Hash Functions. So. If you sent the hash value in a X-JSON header along with an onSuccess() callback, you can extract the hash from the second param to the onSuccess and compare this with the previously retrieved hash to indicate you've got changed data. See [2] for details about PeriodicalUpdater update notification and [3] for the parameters to common callbacks. Regards, Richard. [1]http://en.wikipedia.org/wiki/Hash_function [2]http://www.prototypejs.org/api/ajax/periodicalUpdater http://www.prototypejs.org/api/ajax/periodicalUpdater[3]http://www.prototypejs.org/api/ajax/options http://www.prototypejs.org/api/ajax/options -- - Richard Quadling Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Periodical Updater detect content change
Hope this helps. Ajax/Prototype/JSON PeriodicalUpdater: A working example – log update on a background process http://joekuan.wordpress.com/2009/06/22/ajaxprototypejson-periodicalupdater-a-working-example-log-update-on-a-background-process-part-12/ On Jun 23, 3:20 pm, Aamchi aman.ra...@googlemail.com wrote: Hi, I was wondering if Ajax.PeriodicalUpdater can detect if content has changed since the last update and if so trigger an event. So for example I have a scoreboard which fetches data every 5 seconds and displays this. I would be cool if there could be some kind of notification if content had changed. I know that the new content is stores in responseText but how can I compare it to the previous content... Thanks, Aman --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Periodical Updater detect content change
Well there is a couple of ways to do it Personally if you dont have alot of these elements then 2 hidden elements within the div or page that hold (A) last Ajax.Request time and (B) last change time then just listen to every input element inside the div for a change (untested) $$('#mydiv input').invoke('observe','change',function(element) { $('thehiddenelement').value=the_time_it_was_updated; }); then you can check that on the request function and see if its needed to be sent or not ... (this is a hack!!) Another way is to create a cache on page load of every input element on the page and add it to an array or a json object and store its id,parent,value in the array... HTH Alex - Original Message - From: Aamchi aman.ra...@googlemail.com To: Prototype script.aculo.us prototype-scriptaculous@googlegroups.com Sent: Wednesday, June 24, 2009 8:40 AM Subject: [Proto-Scripty] Re: Periodical Updater detect content change I thought of that too. But this only works in forms doesn't it? How do I detect a changed within a div which is reloaded every few seconds? Would you mind sending me an example? Thanks, Aman On 24 Jun., 08:36, Alex McAuley webmas...@thecarmarketplace.com wrote: There is also a Form.observerhttp://www.prototypejs.org/api/timedObserver/form-observer I used to use this but implemented my own version of it with a cache and some hashing, it didnt take long to write and works perfectly HTH Alex - Original Message - From: Aamchi aman.ra...@googlemail.com To: Prototype script.aculo.us prototype-scriptaculous@googlegroups.com Sent: Tuesday, June 23, 2009 11:19 PM Subject: [Proto-Scripty] Re: Periodical Updater detect content change Thanks, for your response. I'm not 100% sure if I understand correctly what you mean. If I get some data and generate a hash and write this to the JSON header and retrieve this when calling onSuccess, how will I still have the previous hash? From where will I get this? Won't the updated data cause the hash to be overwritten in the JSON header? Or do I have to send two hashes always and compare them? On 23 Jun., 22:57, Richard Quadling rquadl...@googlemail.com wrote: 2009/6/23 Aamchi aman.ra...@googlemail.com Hi, I was wondering if Ajax.PeriodicalUpdater can detect if content has changed since the last update and if so trigger an event. So for example I have a scoreboard which fetches data every 5 seconds and displays this. I would be cool if there could be some kind of notification if content had changed. I know that the new content is stores in responseText but how can I compare it to the previous content... Thanks, Aman Personally, I would do this server side. Assuming you get the data in some sort of structure before either rending some HTML and sending it or just sending it JSON'd, then you should be able to build a hash of the data. See [1] for info on Hash Functions. So. If you sent the hash value in a X-JSON header along with an onSuccess() callback, you can extract the hash from the second param to the onSuccess and compare this with the previously retrieved hash to indicate you've got changed data. See [2] for details about PeriodicalUpdater update notification and [3] for the parameters to common callbacks. Regards, Richard. [1]http://en.wikipedia.org/wiki/Hash_function [2]http://www.prototypejs.org/api/ajax/periodicalUpdater http://www.prototypejs.org/api/ajax/periodicalUpdater[3]http://www.prototypejs.org/api/ajax/options http://www.prototypejs.org/api/ajax/options -- - Richard Quadling Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Periodical Updater detect content change
2009/6/23 Aamchi aman.ra...@googlemail.com: Thanks, for your response. I'm not 100% sure if I understand correctly what you mean. If I get some data and generate a hash and write this to the JSON header and retrieve this when calling onSuccess, how will I still have the previous hash? From where will I get this? Won't the updated data cause the hash to be overwritten in the JSON header? Or do I have to send two hashes always and compare them? On 23 Jun., 22:57, Richard Quadling rquadl...@googlemail.com wrote: 2009/6/23 Aamchi aman.ra...@googlemail.com Hi, I was wondering if Ajax.PeriodicalUpdater can detect if content has changed since the last update and if so trigger an event. So for example I have a scoreboard which fetches data every 5 seconds and displays this. I would be cool if there could be some kind of notification if content had changed. I know that the new content is stores in responseText but how can I compare it to the previous content... Thanks, Aman Personally, I would do this server side. Assuming you get the data in some sort of structure before either rending some HTML and sending it or just sending it JSON'd, then you should be able to build a hash of the data. See [1] for info on Hash Functions. So. If you sent the hash value in a X-JSON header along with an onSuccess() callback, you can extract the hash from the second param to the onSuccess and compare this with the previously retrieved hash to indicate you've got changed data. See [2] for details about PeriodicalUpdater update notification and [3] for the parameters to common callbacks. Regards, Richard. [1]http://en.wikipedia.org/wiki/Hash_function [2]http://www.prototypejs.org/api/ajax/periodicalUpdater http://www.prototypejs.org/api/ajax/periodicalUpdater[3]http://www.prototypejs.org/api/ajax/options http://www.prototypejs.org/api/ajax/options -- - Richard Quadling Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! You add a previousHash:null; to your periodic updater and check that value against the one coming in via the X-JSON header. If it is different, then the data is different. If it is the same, then the data is the same. Either way, once evaluated, same the new hash. Untested (sorry), but adapting the example at [1] ... var o_Updater = new Ajax.PeriodicalUpdater ( 'lastLogin', '/lastLogin.php', { method: 'get', frequency : 3, decay : 2, lastHash : null, onSuccess : function(o_Transport, o_JSON) { // Do we have JSON? if (!!o_JSON) { // Do we have a previous hash? if (!!this.options.lastHash (this.options.lastHash != o_JSON.thisHash)) { // Hashes are different. Maybe activate an effect to show the highlighted data and slowly fade away over time. } // Update hash. this.options.lastHash != o_JSON.thisHash; } } } ); The code on the server would be something like this (I'm using PHP). ?php // Assume we are getting this data from a database. $a_Data = array ( 'Name' = 'Richard Quadling', 'LastPost' = '2009-06-24 10:00:00', ); // Build hash $s_Hash = array('Hash' = md5(serialize($a_Data))); // Generate output. $s_Output = tbodytrtd{$a_Data['Name']}/tdtd{$a_Data['LastPost']}/td/tbody; // X-JSON Header header('X-JSON: ' . json_encode($s_Hash, JSON_FORCE_OBJECT)); // Output results. echo $s_Output; ? The PHP outputs (edited) ... X-JSON: {Hash:a0c23e7f9651f2b65135932917b7f03a} Content-type: text/html tbodytrtdRichard Quadling/tdtd2009-06-24 10:00:00/td/tbody So the X-JSON header is presented as o_JSON in onSuccess() and o_JSON.Hash is 'a0c23e7f9651f2b65135932917b7f03a' And the HTML would go to the container you defined in the PeriodicUpdater Richard. -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en
[Proto-Scripty] Re: Periodical Updater detect content change
Thanks Richard, I will try this out. Really appreciate your help! On 24 Jun., 12:12, Richard Quadling rquadl...@googlemail.com wrote: 2009/6/23 Aamchi aman.ra...@googlemail.com: Thanks, for your response. I'm not 100% sure if I understand correctly what you mean. If I get some data and generate a hash and write this to the JSON header and retrieve this when calling onSuccess, how will I still have the previous hash? From where will I get this? Won't the updated data cause the hash to be overwritten in the JSON header? Or do I have to send two hashes always and compare them? On 23 Jun., 22:57, Richard Quadling rquadl...@googlemail.com wrote: 2009/6/23 Aamchi aman.ra...@googlemail.com Hi, I was wondering if Ajax.PeriodicalUpdater can detect if content has changed since the last update and if so trigger an event. So for example I have a scoreboard which fetches data every 5 seconds and displays this. I would be cool if there could be some kind of notification if content had changed. I know that the new content is stores in responseText but how can I compare it to the previous content... Thanks, Aman Personally, I would do this server side. Assuming you get the data in some sort of structure before either rending some HTML and sending it or just sending it JSON'd, then you should be able to build a hash of the data. See [1] for info on Hash Functions. So. If you sent the hash value in a X-JSON header along with an onSuccess() callback, you can extract the hash from the second param to the onSuccess and compare this with the previously retrieved hash to indicate you've got changed data. See [2] for details about PeriodicalUpdater update notification and [3] for the parameters to common callbacks. Regards, Richard. [1]http://en.wikipedia.org/wiki/Hash_function [2]http://www.prototypejs.org/api/ajax/periodicalUpdater http://www.prototypejs.org/api/ajax/periodicalUpdater[3]http://www.prototypejs.org/api/ajax/options http://www.prototypejs.org/api/ajax/options -- - Richard Quadling Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! You add a previousHash:null; to your periodic updater and check that value against the one coming in via the X-JSON header. If it is different, then the data is different. If it is the same, then the data is the same. Either way, once evaluated, same the new hash. Untested (sorry), but adapting the example at [1] ... var o_Updater = new Ajax.PeriodicalUpdater ( 'lastLogin', '/lastLogin.php', { method : 'get', frequency : 3, decay : 2, lastHash : null, onSuccess : function(o_Transport, o_JSON) { // Do we have JSON? if (!!o_JSON) { // Do we have a previous hash? if (!!this.options.lastHash (this.options.lastHash != o_JSON.thisHash)) { // Hashes are different. Maybe activate an effect to show the highlighted data and slowly fade away over time. } // Update hash. this.options.lastHash != o_JSON.thisHash; } } } ); The code on the server would be something like this (I'm using PHP). ?php // Assume we are getting this data from a database. $a_Data = array ( 'Name' = 'Richard Quadling', 'LastPost' = '2009-06-24 10:00:00', ); // Build hash $s_Hash = array('Hash' = md5(serialize($a_Data))); // Generate output. $s_Output = tbodytrtd{$a_Data['Name']}/tdtd{$a_Data['LastPost']}/td/tbody; // X-JSON Header header('X-JSON: ' . json_encode($s_Hash, JSON_FORCE_OBJECT)); // Output results. echo $s_Output; ? The PHP outputs (edited) ... X-JSON: {Hash:a0c23e7f9651f2b65135932917b7f03a} Content-type: text/html tbodytrtdRichard Quadling/tdtd2009-06-24 10:00:00/td/tbody So the X-JSON header is presented as o_JSON in onSuccess() and o_JSON.Hash is 'a0c23e7f9651f2b65135932917b7f03a' And the HTML would go to the container you defined in the PeriodicUpdater Richard. -- - Richard Quadling Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To
[Proto-Scripty] Re: Periodical Updater detect content change
Hi Richard, Your example works perfectly :-) Just a few minor things that I had to change to make it actually work (not being fussy, just if someone else finds this useful as well and wants to try it out): -The this operator didn't work for me, I replaced it with o_Updater - In the PHP the array key which stores the hash is 'Hash' and not 'thisHash', so replace thisHash with Hash in the js-code - And when updating hash: o_Updater.options.lastHash = o_JSON.thisHash (instead of o_Updater.options.lastHash != o_JSON.thisHash) Thanks again. Aman On 24 Jun., 12:12, Richard Quadling rquadl...@googlemail.com wrote: 2009/6/23 Aamchi aman.ra...@googlemail.com: Thanks, for your response. I'm not 100% sure if I understand correctly what you mean. If I get some data and generate a hash and write this to the JSON header and retrieve this when calling onSuccess, how will I still have the previous hash? From where will I get this? Won't the updated data cause the hash to be overwritten in the JSON header? Or do I have to send two hashes always and compare them? On 23 Jun., 22:57, Richard Quadling rquadl...@googlemail.com wrote: 2009/6/23 Aamchi aman.ra...@googlemail.com Hi, I was wondering if Ajax.PeriodicalUpdater can detect if content has changed since the last update and if so trigger an event. So for example I have a scoreboard which fetches data every 5 seconds and displays this. I would be cool if there could be some kind of notification if content had changed. I know that the new content is stores in responseText but how can I compare it to the previous content... Thanks, Aman Personally, I would do this server side. Assuming you get the data in some sort of structure before either rending some HTML and sending it or just sending it JSON'd, then you should be able to build a hash of the data. See [1] for info on Hash Functions. So. If you sent the hash value in a X-JSON header along with an onSuccess() callback, you can extract the hash from the second param to the onSuccess and compare this with the previously retrieved hash to indicate you've got changed data. See [2] for details about PeriodicalUpdater update notification and [3] for the parameters to common callbacks. Regards, Richard. [1]http://en.wikipedia.org/wiki/Hash_function [2]http://www.prototypejs.org/api/ajax/periodicalUpdater http://www.prototypejs.org/api/ajax/periodicalUpdater[3]http://www.prototypejs.org/api/ajax/options http://www.prototypejs.org/api/ajax/options -- - Richard Quadling Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! You add a previousHash:null; to your periodic updater and check that value against the one coming in via the X-JSON header. If it is different, then the data is different. If it is the same, then the data is the same. Either way, once evaluated, same the new hash. Untested (sorry), but adapting the example at [1] ... var o_Updater = new Ajax.PeriodicalUpdater ( 'lastLogin', '/lastLogin.php', { method : 'get', frequency : 3, decay : 2, lastHash : null, onSuccess : function(o_Transport, o_JSON) { // Do we have JSON? if (!!o_JSON) { // Do we have a previous hash? if (!!this.options.lastHash (this.options.lastHash != o_JSON.thisHash)) { // Hashes are different. Maybe activate an effect to show the highlighted data and slowly fade away over time. } // Update hash. this.options.lastHash != o_JSON.thisHash; } } } ); The code on the server would be something like this (I'm using PHP). ?php // Assume we are getting this data from a database. $a_Data = array ( 'Name' = 'Richard Quadling', 'LastPost' = '2009-06-24 10:00:00', ); // Build hash $s_Hash = array('Hash' = md5(serialize($a_Data))); // Generate output. $s_Output = tbodytrtd{$a_Data['Name']}/tdtd{$a_Data['LastPost']}/td/tbody; // X-JSON Header header('X-JSON: ' . json_encode($s_Hash, JSON_FORCE_OBJECT)); // Output results. echo $s_Output; ? The PHP outputs (edited) ... X-JSON: {Hash:a0c23e7f9651f2b65135932917b7f03a} Content-type: text/html tbodytrtdRichard Quadling/tdtd2009-06-24 10:00:00/td/tbody So the X-JSON header is presented as o_JSON in onSuccess() and o_JSON.Hash is 'a0c23e7f9651f2b65135932917b7f03a' And
[Proto-Scripty] Re: Periodical Updater detect content change
2009/6/23 Aamchi aman.ra...@googlemail.com Hi, I was wondering if Ajax.PeriodicalUpdater can detect if content has changed since the last update and if so trigger an event. So for example I have a scoreboard which fetches data every 5 seconds and displays this. I would be cool if there could be some kind of notification if content had changed. I know that the new content is stores in responseText but how can I compare it to the previous content... Thanks, Aman Personally, I would do this server side. Assuming you get the data in some sort of structure before either rending some HTML and sending it or just sending it JSON'd, then you should be able to build a hash of the data. See [1] for info on Hash Functions. So. If you sent the hash value in a X-JSON header along with an onSuccess() callback, you can extract the hash from the second param to the onSuccess and compare this with the previously retrieved hash to indicate you've got changed data. See [2] for details about PeriodicalUpdater update notification and [3] for the parameters to common callbacks. Regards, Richard. [1] http://en.wikipedia.org/wiki/Hash_function [2] http://www.prototypejs.org/api/ajax/periodicalUpdater http://www.prototypejs.org/api/ajax/periodicalUpdater[3] http://www.prototypejs.org/api/ajax/options http://www.prototypejs.org/api/ajax/options -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Periodical Updater detect content change
Thanks, for your response. I'm not 100% sure if I understand correctly what you mean. If I get some data and generate a hash and write this to the JSON header and retrieve this when calling onSuccess, how will I still have the previous hash? From where will I get this? Won't the updated data cause the hash to be overwritten in the JSON header? Or do I have to send two hashes always and compare them? On 23 Jun., 22:57, Richard Quadling rquadl...@googlemail.com wrote: 2009/6/23 Aamchi aman.ra...@googlemail.com Hi, I was wondering if Ajax.PeriodicalUpdater can detect if content has changed since the last update and if so trigger an event. So for example I have a scoreboard which fetches data every 5 seconds and displays this. I would be cool if there could be some kind of notification if content had changed. I know that the new content is stores in responseText but how can I compare it to the previous content... Thanks, Aman Personally, I would do this server side. Assuming you get the data in some sort of structure before either rending some HTML and sending it or just sending it JSON'd, then you should be able to build a hash of the data. See [1] for info on Hash Functions. So. If you sent the hash value in a X-JSON header along with an onSuccess() callback, you can extract the hash from the second param to the onSuccess and compare this with the previously retrieved hash to indicate you've got changed data. See [2] for details about PeriodicalUpdater update notification and [3] for the parameters to common callbacks. Regards, Richard. [1]http://en.wikipedia.org/wiki/Hash_function [2]http://www.prototypejs.org/api/ajax/periodicalUpdater http://www.prototypejs.org/api/ajax/periodicalUpdater[3]http://www.prototypejs.org/api/ajax/options http://www.prototypejs.org/api/ajax/options -- - Richard Quadling Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---