esther.fuldauer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-18 21:07 UTC
[Prototype]Ajax.Updater: contents not showing
Hi, I''m new to Prototype and I''m trying to use Ajax.Updater to update a pege with new content depending on the day of the week. I''m doing this with an html for each day, but maybe you could suggest how to do this with a single xml file? In any case, my problem is that the code below doesn''t work and i don''t know why. In the function showResponse() the alert displays the html contents, so the updater is working correctly only that the ''content'' container is not displaying. What am I doing wrong? <html> <head> <script src="lib/prototype/prototype.js" type="text/javascript"></ script> <script language="JavaScript" type="text/javascript"> today=new Date(); weekday=today.getDay(); weekdays=[''sunday'',''monday'',''tuesday'',''wednesday'',''thursday'',''friday'',''saturday'']; var ajax = new Ajax.Updater(''content'',weekdays[0]+''.htm'', { // options method:''get'', onComplete: showResponse }); function showResponse(req) { alert(req.responseText); $(''content'').innerHTML = req.responseText; } </script> </head> <body> <div id="content"></div> </body> </html> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ajax.Updater is basically a wrapper for Ajax.Request which calls an insertion function (default is Element.update) on the element passed, so your onComplete function is not necessary. You are basically updating that element twice but I think it should still update.. perhaps the other problem is that your script is running before the content div is loaded? Try placing your script block at the end of the body or at least anywhere after the <div>. Also there is usually no reason to store the Ajax requests in a variable. Your Ajax.Updater call could then look like this: new Ajax.Updater(''content'',weekdays[weekday]+''.htm'',{method: get}); or, if you want to do something with the responseText before updating: new Ajax.Updater(''content'',weekdays[weekday]+''.htm'',{ method: get, insertion: function(element,update){ alert(element.id+'' gets ''+update); Element.update(element,update); } }); Colin esther.fuldauer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Hi, > > I''m new to Prototype and I''m trying to use Ajax.Updater to update a > pege with new content depending on the day of the week. I''m doing this > with an html for each day, but maybe you could suggest how to do this > with a single xml file? > In any case, my problem is that the code below doesn''t work and i > don''t know why. > In the function showResponse() the alert displays the html contents, > so the updater is working correctly only that the ''content'' container > is not displaying. > What am I doing wrong? > > > <html> > <head> > <script src="lib/prototype/prototype.js" type="text/javascript"></ > script> > <script language="JavaScript" type="text/javascript"> > today=new Date(); > weekday=today.getDay(); > weekdays=[''sunday'',''monday'',''tuesday'',''wednesday'',''thursday'',''friday'',''saturday'']; > var ajax = new Ajax.Updater(''content'',weekdays[0]+''.htm'', > { // options > method:''get'', > onComplete: showResponse > }); > > function showResponse(req) > { > alert(req.responseText); > $(''content'').innerHTML = req.responseText; > > } > > </script> > </head> > <body> > <div id="content"></div> > </body> > </html> > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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, You were right. By placing the script after the div, the content finaly got updated. However I tryed your shortened code but it didn''t work. I don''t know why, maybe the onComplete does make a difference. By all logic it should work. Thanks for the explanation and the tip about changing the responseText. On Feb 18, 11:23 pm, Colin Mollenhour <eliteii...-NPSFNn/7+NYVo650/ln6uw@public.gmane.org> wrote:> Ajax.Updater is basically a wrapper for Ajax.Request which calls an > insertion function (default is Element.update) on the element passed, so > your onComplete function is not necessary. You are basically updating > that element twice but I think it should still update.. perhaps the > other problem is that your script is running before the content div is > loaded? Try placing your script block at the end of the body or at least > anywhere after the <div>. Also there is usually no reason to store the > Ajax requests in a variable. Your Ajax.Updater call could then look like > this: > > new Ajax.Updater(''content'',weekdays[weekday]+''.htm'',{method: get}); > > or, if you want to do something with the responseText before updating: > > new Ajax.Updater(''content'',weekdays[weekday]+''.htm'',{ > method: get, > insertion: function(element,update){ > alert(element.id+'' gets ''+update); > Element.update(element,update); > } > > }); > > Colin > > esther.fulda...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > Hi, > > > I''m new to Prototype and I''m trying to use Ajax.Updater to update a > > pege with new content depending on the day of the week. I''m doing this > > with an html for each day, but maybe you could suggest how to do this > > with a single xml file? > > In any case, my problem is that the code below doesn''t work and i > > don''t know why. > > In the function showResponse() the alert displays the html contents, > > so the updater is working correctly only that the ''content'' container > > is not displaying. > > What am I doing wrong? > > > <html> > > <head> > > <script src="lib/prototype/prototype.js" type="text/javascript"></ > > script> > > <script language="JavaScript" type="text/javascript"> > > today=new Date(); > > weekday=today.getDay(); > > weekdays=[''sunday'',''monday'',''tuesday'',''wednesday'',''thursday'',''friday'',''saturday'']; > > var ajax = new Ajax.Updater(''content'',weekdays[0]+''.htm'', > > { // options > > method:''get'', > > onComplete: showResponse > > }); > > > function showResponse(req) > > { > > alert(req.responseText); > > $(''content'').innerHTML = req.responseText; > > > } > > > </script> > > </head> > > <body> > > <div id="content"></div> > > </body> > > </html>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<!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"> Oh, looks like I forgot to add the quotes around "get"...<br> <br> Colin<br> <br> Esther wrote: <blockquote cite="mid:1171839382.234126.310540-5wKdhOQDh7Nfvz3QPplmsGB/v6IoIuQBVpNB7YpNyf8@public.gmane.org" type="cite"> <pre wrap=""> Colin, You were right. By placing the script after the div, the content finaly got updated. However I tryed your shortened code but it didn''t work. I don''t know why, maybe the onComplete does make a difference. By all logic it should work. Thanks for the explanation and the tip about changing the responseText. On Feb 18, 11:23 pm, Colin Mollenhour <a class="moz-txt-link-rfc2396E" href="mailto:eliteii...-NPSFNn/7+NYVo650/ln6uw@public.gmane.org"><eliteii...-NPSFNn/7+NYVo650/ln6uw@public.gmane.org></a> wrote: </pre> <blockquote type="cite"> <pre wrap="">Ajax.Updater is basically a wrapper for Ajax.Request which calls an insertion function (default is Element.update) on the element passed, so your onComplete function is not necessary. You are basically updating that element twice but I think it should still update.. perhaps the other problem is that your script is running before the content div is loaded? Try placing your script block at the end of the body or at least anywhere after the <div>. Also there is usually no reason to store the Ajax requests in a variable. Your Ajax.Updater call could then look like this: new Ajax.Updater(''content'',weekdays[weekday]+''.htm'',{method: get}); or, if you want to do something with the responseText before updating: new Ajax.Updater(''content'',weekdays[weekday]+''.htm'',{ method: get, insertion: function(element,update){ alert(element.id+'' gets ''+update); Element.update(element,update); } }); Colin <a class="moz-txt-link-abbreviated" href="mailto:esther.fulda...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org">esther.fulda...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</a> wrote: </pre> <blockquote type="cite"> <pre wrap="">Hi, </pre> </blockquote> <blockquote type="cite"> <pre wrap="">I''m new to Prototype and I''m trying to use Ajax.Updater to update a pege with new content depending on the day of the week. I''m doing this with an html for each day, but maybe you could suggest how to do this with a single xml file? In any case, my problem is that the code below doesn''t work and i don''t know why. In the function showResponse() the alert displays the html contents, so the updater is working correctly only that the ''content'' container is not displaying. What am I doing wrong? </pre> </blockquote> <blockquote type="cite"> <pre wrap=""><html> <head> <script src="lib/prototype/prototype.js" type="text/javascript"></ script> <script language="JavaScript" type="text/javascript"> today=new Date(); weekday=today.getDay(); weekdays=[''sunday'',''monday'',''tuesday'',''wednesday'',''thursday'',''friday'',''saturday'']; var ajax = new Ajax.Updater(''content'',weekdays[0]+''.htm'', { // options method:''get'', onComplete: showResponse }); </pre> </blockquote> <blockquote type="cite"> <pre wrap="">function showResponse(req) { alert(req.responseText); $(''content'').innerHTML = req.responseText; </pre> </blockquote> <blockquote type="cite"> <pre wrap="">} </pre> </blockquote> <blockquote type="cite"> <pre wrap=""></script> </head> <body> <div id="content"></div> </body> </html> </pre> </blockquote> </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>
Christophe Porteneuve
2007-Feb-19 08:14 UTC
Re: [Prototype]Ajax.Updater: contents not showing
Hey Esther, All AJAX aside, why are you using AJAX to do something that could clearly be done server-side? I mean, you''re just loading *the entire page contents* based on the freakin'' weekday! This can be done server-side using SSI''s, PHP, or whatnot. Even if you need to work based on the visitor''s TZ''s weekday, HTTP headers will give you his/her GMT offset anyway... This would take <10 lines in any server-side tech. Even from an accessibility standpoint, this is *not* comfort, this is core functionality here (the whole contents!), so this should not depend on JS and AJAX being available. From a visual standpoint, this also means that with any network latency, the visitor will first encounter an empty page, and have no visual clue that the actual contents is loading from then on... Not too good. In short, this sounds to me like a textbook case of AJAX used where it''s clearly not the relevant path. Sometimes we''re so bent on implementation, we forget the bigger picture. I may be wrong (not having the bigger picture), but from the problem you described, I fail to see why AJAX is needed at all! Just my two cents, -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Christophe, Yes, I know it sounds silly, but my company contracted a useless service provider before I came on board that I have to live with for the time being. A CMS system for dummies which I can''t add any server-side scripts to. So imagine how I feel having to update stupid text daily by hand. Hopefully this will change in a couple months and I can have a proper Apache server which is completely under my control. The contents are only 3 sentences long, so that won''t take too much to load. At any rate, I will have a text there saying "loading..." Do you see the big picture now? I''m stuck with server-side scripting at the moment. A good chance to learn a bit more of javascript and AJAX. By the way, now that I have you in the thread, do you know or could indicate me whree I could find some example on how to do this using xml instead of html for the data? Cheers :) 2007/2/19, Christophe Porteneuve <tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org>:> > > Hey Esther, > > All AJAX aside, why are you using AJAX to do something that could > clearly be done server-side? > > I mean, you''re just loading *the entire page contents* based on the > freakin'' weekday! This can be done server-side using SSI''s, PHP, or > whatnot. Even if you need to work based on the visitor''s TZ''s weekday, > HTTP headers will give you his/her GMT offset anyway... This would take > <10 lines in any server-side tech. > > Even from an accessibility standpoint, this is *not* comfort, this is > core functionality here (the whole contents!), so this should not depend > on JS and AJAX being available. > > From a visual standpoint, this also means that with any network latency, > the visitor will first encounter an empty page, and have no visual clue > that the actual contents is loading from then on... Not too good. > > In short, this sounds to me like a textbook case of AJAX used where it''s > clearly not the relevant path. > > Sometimes we''re so bent on implementation, we forget the bigger picture. > I may be wrong (not having the bigger picture), but from the problem > you described, I fail to see why AJAX is needed at all! > > Just my two cents, > > -- > Christophe Porteneuve a.k.a. TDD > "[They] did not know it was impossible, so they did it." --Mark Twain > Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org > > > >-- Esther Fuldauer Web Developer & Designer tlf. 972355421 movil 679066844 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Feb-19 09:37 UTC
Re: [Prototype]Ajax.Updater: contents not showing
Hey Esther, Esther Fuldauer a écrit :> Do you see the big picture now? I''m stuck with server-side scripting at > the moment.Client-side, actually :-)> By the way, now that I have you in the thread, do you know or could"Now that you have *me* in the thread?" Uh?!> indicate me whree I could find some example on how to do this using xml > instead of html for the data?Well, I can''t see how useful that would be. I mean, you''re already applying a band-aid over it because you can''t, so far, do it properly (server-side). Why would you want to add extra complexity by moving it to XML? This doesn''t appear to be useful at all. I mean: 1) The data you''re getting back are to be presented as HTML 2) Their semantics is probably properly represented by <p> and the like. 3) The data isn''t generated by something else, then hand-converted to HTML, is it? It''s created as HTML already, I suppose? So why adding unnecessary juggling? 4) Client-side processing of this XML would require manual exploration of its DOM (I assume you have no control over the client-side browsers, so XPath or E4X are out of the question), and XHTML DOM building (even with script.aculo.us'' Builder...). Or even worse: XSL/T transforms! Yay! So, in a word: are you *sure* you want to add this extraneous complexity? -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yeah, You are right, to update a tiny pice of text daily I''m best off with the html bits instead of xml I was thinking more of another case I have where I need to update the html each time the page gets loaded. If the pieces I need to rotate on the page are more than 20, how do you suggest I go about it? Also an html for each piece? Thanks 2007/2/19, Christophe Porteneuve <tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org>:> > > Hey Esther, > > Esther Fuldauer a écrit : > > Do you see the big picture now? I''m stuck with server-side scripting at > > the moment. > > Client-side, actually :-) > > > By the way, now that I have you in the thread, do you know or could > > "Now that you have *me* in the thread?" Uh?! > > > indicate me whree I could find some example on how to do this using xml > > instead of html for the data? > > Well, I can''t see how useful that would be. I mean, you''re already > applying a band-aid over it because you can''t, so far, do it properly > (server-side). Why would you want to add extra complexity by moving it > to XML? This doesn''t appear to be useful at all. > > I mean: > > 1) The data you''re getting back are to be presented as HTML > 2) Their semantics is probably properly represented by <p> and the like. > 3) The data isn''t generated by something else, then hand-converted to > HTML, is it? It''s created as HTML already, I suppose? So why adding > unnecessary juggling? > 4) Client-side processing of this XML would require manual exploration > of its DOM (I assume you have no control over the client-side browsers, > so XPath or E4X are out of the question), and XHTML DOM building (even > with script.aculo.us'' Builder...). Or even worse: XSL/T transforms! Yay! > > So, in a word: are you *sure* you want to add this extraneous complexity? > > -- > Christophe Porteneuve aka TDD > tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org > > > >-- Esther Fuldauer Web Developer & Designer tlf. 972355421 movil 679066844 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-Feb-19 10:15 UTC
Re: [Prototype]Ajax.Updater: contents not showing
Hey Esther, Esther Fuldauer a écrit :> I was thinking more of another case I have where I need to update the > html each time the page gets loaded. If the pieces I need to rotate on > the page are more than 20, how do you suggest I go about it? Also an > html for each piece?It really depends on the semantics of your bits. I mean, eventually they''re HTML in the page. So how are they represented originally? Are those static XHTML fragments? If yes, don''t bother: get them! If you worry about the 2-resource-per-domain HTTP recommendation, you may decide to concatenate them in a file with delimiters, fetch the whole thing, split client-side (String.split is there for you), and do updates yourself instead of using Ajax.Updater (e.g. use Ajax.Request with a custom onSuccess callback that splits, then loops over fragments and containers and calls update manually). The short point is: if there is no *compelling* reason to use something else than HTML for your fragments, then *go HTML*. Actually, go XHTML (no ambiguity makes for faster, more reliable parsing and DOM building by the browser). -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I do have a tendency of complicating things hehe ;) I''ll forget the xml then and use an xhtml file with the split. Thanks Christophe for your reasoning. :) 2007/2/19, Christophe Porteneuve <tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org>:> > > Hey Esther, > > Esther Fuldauer a écrit : > > I was thinking more of another case I have where I need to update the > > html each time the page gets loaded. If the pieces I need to rotate on > > the page are more than 20, how do you suggest I go about it? Also an > > html for each piece? > > It really depends on the semantics of your bits. I mean, eventually > they''re HTML in the page. So how are they represented originally? Are > those static XHTML fragments? If yes, don''t bother: get them! > > If you worry about the 2-resource-per-domain HTTP recommendation, you > may decide to concatenate them in a file with delimiters, fetch the > whole thing, split client-side (String.split is there for you), and do > updates yourself instead of using Ajax.Updater (e.g. use Ajax.Request > with a custom onSuccess callback that splits, then loops over fragments > and containers and calls update manually). > > The short point is: if there is no *compelling* reason to use something > else than HTML for your fragments, then *go HTML*. Actually, go XHTML > (no ambiguity makes for faster, more reliable parsing and DOM building > by the browser). > > -- > Christophe Porteneuve aka TDD > tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org > > > >-- Esther Fuldauer Web Developer & Designer tlf. 972355421 movil 679066844 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Please elaborate on this: On Feb 19, 2007, at 5:15 AM, Christophe Porteneuve wrote:> If you worry about the 2-resource-per-domain HTTP recommendation, you > may decide to concatenate them in a file with delimiters, fetch the > whole thing, split client-side (String.split is there for you), and do > updates yourself instead of using Ajax.Updater (e.g. use Ajax.Request > with a custom onSuccess callback that splits, then loops over fragments > and containers and calls update manually). >I haven''t heard of this before, but it is ringing a tiny bell in my head about why certain things don''t always work the way I imagine they should. Thanks! Walter --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---