Graham
2007-Mar-01 14:48 UTC
Ajax.PeriodicalUpdater using Effect.Highlight to highlight newly loaded div
Hi folks. So far I have managed to get dataloading into a div froma php script. This script just passes the time on the server in a div to the javascript below. I am trying to get the last loaded data to call Effect.Highlight but it seems to highlight the 2nd last data instead. Can anyone see what''s going wrong here? I''ve tried everywhere to solve this. Check the code in action here http://gramac4.freeserverhost.com/test.php. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <link href="includes/initial.css" rel="stylesheet" type="text/css" /><link href="includes/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> .testtime { border:1px solid #000; padding: 5px; margin-bottom: 2px; } </style> <script src="includes/prototype.js" type="text/javascript"></script> <script src="includes/scriptaculous.js" type="text/javascript"></ script> <script type="text/javascript"> var ajaxPopulater = function (id,url){ url = url + ''?StopCache='' + new Date; new Ajax.PeriodicalUpdater(id, url, { method: ''post'', frequency: 1, asynchronous: true, insertion: Insertion.Top, onSuccess: highlight, decay: 1 }); } var highlight = function(originalRequest){ new Effect.Highlight(''test''); } </script> <title></title> </head> <body onload="javascript:ajaxPopulater(''latest'',''/ajax.php'')"> <div id="latest"></div> </body> </html> ajax.php <?php $time = time(); echo ''<div class="testtime" id="test">'' . $time . ''</div>'' . "\n"; ?> Thanks in advance! --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
dave crane
2007-Mar-01 16:19 UTC
Re: Ajax.PeriodicalUpdater using Effect.Highlight to highlight newly loaded div
On Thursday 01 March 2007 14:48, Graham wrote:> Hi folks. So far I have managed to get dataloading into a div froma > php script. This script just passes the time on the server in a div to > the javascript below. I am trying to get the last loaded data to call > Effect.Highlight but it seems to highlight the 2nd last data instead. > Can anyone see what''s going wrong here? I''ve tried everywhere to solve > this. > Check the code in action here http://gramac4.freeserverhost.com/test.php.Hi Graham, Just had a quick look at this in Firebug. It looks like all your DIV tags are coming back with an ID of ''test''. so the Effect is just going to go for the first one with that name. Looks like a race condition is underway here - although the updateContent() gets called before onComplete(), the first time the Effect is invoked, the content hasn''t been rendered yet, so it selects the previous one. If you increment the id of the div each time (test_1, test_2) etc., you''ll avoid this kind of confusion - or you could pass the id of the incoming DIV to be highlighted as an X-JSON header, maybe? HTH Dave -- ---------------------- Author Ajax in Action http://manning.com/crane Ajax in Practice http://manning.com/crane2 Prototype & Scriptaculous in Action http://manning.com/crane3 --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Graham
2007-Mar-01 17:57 UTC
Re: Ajax.PeriodicalUpdater using Effect.Highlight to highlight newly loaded div
Aahh. I see. Well I''ll take a look at that tomorrow and work out some kind of loop to increment the dive number. Thanks for your help Dave. Graham On Mar 1, 4:19 pm, dave crane <d...-qrf20pp95eSLQvtTh0HkdajZmZ73YKuj@public.gmane.org> wrote:> Hi Graham, > > Just had a quick look at this in Firebug. It looks like all your DIV tags are > coming back with an ID of ''test''. so the Effect is just going to go for the first > one with that name. Looks like a race condition is underway here - although the > updateContent() gets called before onComplete(), the first time the Effect is > invoked, the content hasn''t been rendered yet, so it selects the previous one. > > If you increment the id of the div each time (test_1, test_2) etc., you''ll avoid > this kind of confusion - or you could pass the id of the incoming DIV to be > highlighted as an X-JSON header, maybe? > > HTH > > Dave--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Colin Mollenhour
2007-Mar-01 18:41 UTC
Re: Ajax.PeriodicalUpdater using Effect.Highlight to highlight newly loaded div
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> I''d recommend not using IDs at all for simplicity. Instead, use the DOM traversal methods:<br> <pre wrap="">var highlight = function(originalRequest){ new Effect.Highlight($(id).down()); } Colin </pre> <br> Graham wrote: <blockquote cite="mid:1172771836.256966.11890-nbjlO0B5Z9/XntctwulLdWB/v6IoIuQBVpNB7YpNyf8@public.gmane.org" type="cite"> <pre wrap="">Aahh. I see. Well I''ll take a look at that tomorrow and work out some kind of loop to increment the dive number. Thanks for your help Dave. Graham On Mar 1, 4:19 pm, dave crane <a class="moz-txt-link-rfc2396E" href="mailto:d...-qrf20pp95eSLQvtTh0HkdajZmZ73YKuj@public.gmane.org"><d...-qrf20pp95eSLQvtTh0HkdajZmZ73YKuj@public.gmane.org></a> wrote: </pre> <blockquote type="cite"> <pre wrap="">Hi Graham, Just had a quick look at this in Firebug. It looks like all your DIV tags are coming back with an ID of ''test''. so the Effect is just going to go for the first one with that name. Looks like a race condition is underway here - although the updateContent() gets called before onComplete(), the first time the Effect is invoked, the content hasn''t been rendered yet, so it selects the previous one. If you increment the id of the div each time (test_1, test_2) etc., you''ll avoid this kind of confusion - or you could pass the id of the incoming DIV to be highlighted as an X-JSON header, maybe? HTH Dave </pre> </blockquote> <pre wrap=""><!----> </pre> </blockquote> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. <br> To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en <br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>