I''m having trouble preventing my Ajax.Request from caching my data file, which is updated and needs to be reloaded every 2-3 seconds. Here''s what I have now: function createSidebar() { new Ajax.Request(''sample.json'', { method:''get'', requestHeaders:{"Cache-control":"no-cache"}, requestHeaders:{"If-Modified-Since":"Sat, 1 Jan 2000"}, onSuccess: function(transport) { json = transport.responseText.evalJSON(); updateTables(); }, onFailure: function() { alert(''There was a problem loading the XML file.'') } }); } window.setInterval("createSidebar()", 2000); I have no idea if I''m using those requestHeaders correctly. I couldn''t find any examples to go on. Safari seems to be pretty good about not caching the file, but Firefox might sit there for 15-20 seconds before showing any change. Any help would be really appreciated. Thanks, Eric --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
How about putting a time stamp at the end of the url? Like - var today = new date(); var rand = today.getTime(); var url = ''sample.json?rand=''+rand; new Ajax.Request(url, {.... Thanks, Mandy. ________________________________ From: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org on behalf of emont88 Sent: Tue 4/17/2007 9:52 AM To: Ruby on Rails: Spinoffs Subject: [Rails-spinoffs] Ajax.Request caching I''m having trouble preventing my Ajax.Request from caching my data file, which is updated and needs to be reloaded every 2-3 seconds. Here''s what I have now: function createSidebar() { new Ajax.Request(''sample.json'', { method:''get'', requestHeaders:{"Cache-control":"no-cache"}, requestHeaders:{"If-Modified-Since":"Sat, 1 Jan 2000"}, onSuccess: function(transport) { json = transport.responseText.evalJSON(); updateTables(); }, onFailure: function() { alert(''There was a problem loading the XML file.'') } }); } window.setInterval("createSidebar()", 2000); I have no idea if I''m using those requestHeaders correctly. I couldn''t find any examples to go on. Safari seems to be pretty good about not caching the file, but Firefox might sit there for 15-20 seconds before showing any change. Any help would be really appreciated. Thanks, Eric --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Eric, emont88 a écrit :> requestHeaders:{"Cache-control":"no-cache"}, > requestHeaders:{"If-Modified-Since":"Sat, 1 Jan 2000"},Several issues here: 1) you don''t define two headers, you define the options twice; the second time overwrites the first time. When you need multiple headers, just go: requestHeaders: { name: ''value'', name2: ''value2''... } 2) Technically, these headers are not the most appropriate. - The no-cache value of Cache-Control simply forces the server to *revalidate* anyway, which may not be good enough is the server layer is not properly coded. - The If-Modified-Since request header only works if the cache for the URL holds a properly defined Last-Modified header. Try with: requestHeaders: { ''Cache-Control'': ''no-store'' } Two neat things to look at: http://www.mnot.net/cache_docs/ (really good write-up, although it incorrectly states that Cache-Control is response-only) http://tools.ietf.org/html/rfc2616 (HTTP 1.1 spec)> Safari seems to be pretty good about not caching the file, but Firefox > might sit there for 15-20 seconds before showing any change.I assume you mean for 15 to 20" using your AJAX requests again won''t hit fresh data? -- 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 -~----------~----~----~----~------~----~------~--~---
Thanks! Those links were really helpful and everything is working now. -Eric --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---