1

I'm using an ajax call to call a php script which waits 40 seconds via sleep and then outputs RELOAD. In JavaScript, the output is checked to be RELOAD, and if so, the call starts again.

This works quite fine on every page I use this. But in Firefox, there is one problem in a specific case.

I am on this page which does those calls, then I click on a link to get to another page. After that, I go back via clicking on the History (Back-)Button. In this case, the calls do start, but firefox seems to have cached the result and immediately outputs RELOAD. This results in calls which take only a few milliseconds to load and i do not get any actualized content. It does not even connect to the server (I changed the php file while the ajax calls kept on going but it took no effect).

So Firefox seems to use cached output ONLY in the case you use the back button (or also javascript:history.back()). If I load the page normal (via link or entering the url in the address bar), the calls do get correctly to the server and get the actual content.

Is there a way I can overwrite this behaviour from PHP or JavaScript? I am using jQuery.ajax() and I have set the "cache:false"-option.

Thank you for your help!

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Florian Müller
  • 7,448
  • 25
  • 78
  • 120
  • 2
    Cache busting, `$.ajax({... cache:false, ...});`. – Rob W Jul 27 '12 at 12:29
  • Edit: I have already set this option, I forgot to mention. – Florian Müller Jul 27 '12 at 12:29
  • 1
    Have you tried something simple like adding a parameter to the URL with an incrementing value so that the URL is different every time? – Pointy Jul 27 '12 at 12:30
  • It sounds like you want `$(document).ready()` to fire on `history.back()`. Check http://stackoverflow.com/questions/158319/cross-browser-onload-event-and-the-back-button/2218733#2218733 or http://stackoverflow.com/questions/158319/cross-browser-onload-event-and-the-back-button/170478#170478 – Dutchie432 Jul 27 '12 at 12:31
  • This is actually the last solution I would use, because this is not really nice programming at all. – Florian Müller Jul 27 '12 at 12:31
  • Can I ask what your use case is for this? I sounds like a strange way to get your page to reload some data. – Kieran Jul 27 '12 at 13:42
  • I've got a website which has a 40-seconds polling ajax call for notifications, just as facebook does. If the user hits the back button, the notifications should also work on this page then, right? And when the call is cached, no new data is gotten, so you wont see new notifications after clicking a back button in Firefox. – Florian Müller Jul 27 '12 at 23:07

1 Answers1

0

I just solved it by adding a random number to the URL. This solution does actually work, but it's not a very beautiful solution at all.

Florian Müller
  • 7,448
  • 25
  • 78
  • 120