0

I have a page with a fairly large amount of images (around 50), each image followed by a form. It's a basic quiz, where the input is sent to a PHP file using $.ajax and matched against the contents of a MySQL database.

Upon successful match (i.e. correct answer), the form is replaced with information from the DB, supplied by the PHP script. If a question has previously been answered correctly, the information is retrieved from the start using PHP.

Nothing too crazy.

However, while everything works fine while on the page, the browser (pretty much any browser) appears to be caching the content, so that when you leave the page and later return, the answered questions are still presented with a form, as opposed to the content. As far as I can tell, the browser caches the content upon load, and not the stuff that gets added while on the page. I can see the answers in the DB just fine.

I wouldn't mind having the images cached, but the content needs to be updated on every page load. How do I do that?

I hope that makes sense.

Thanks.

  • 1
    Maybe this will help: http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers – Sven van Zoelen Dec 07 '12 at 15:59
  • Thanks. I added the PHP version to the site, but the page still doesn't correspond with the contents of the database. Meaning, if I answer a question and reload the page, it doesn't show up as being answered. If i then log in with the same user settings using a different browser, it shows up as being answered. I have no idea why. – user1885905 Dec 08 '12 at 18:58

1 Answers1

0

You have to set a header that specifies no cache. If you're using jQuery you can set it like this:

$.ajaxSetup({ cache: false });

Try meta tags:

<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
Expedito
  • 7,493
  • 5
  • 27
  • 40
  • I do have cache:false in my $.ajax call, but that's not the problem. It's the page itself, which appears to be cached. – user1885905 Dec 08 '12 at 18:55
  • Still no luck. I've rewritten most of the site, so that all the questions are loaded through $.ajax, as they're requested by clicking on a menu. That part works now, in a roundabout way. But the CSS reflecting the state of each question in the menu (green when answered correctly), which is not loaded through $.ajax, remains cached. Meaning, questions recently answered correctly won't turn green for a while. – user1885905 Dec 09 '12 at 23:18