1

I use AJAX for my website and my website some part load after document is ready by AJAX and those parts are dynamic.

Example one part: Hello #USERNAME# this is different for every ID, When i log in to first ID show my username but when log in to second ID this name do not change and show first ID username.

I disabled cache in all PHP pages by above code:

<?php 
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

But cache is not disabled.

2
  • 2
    PRO TIP: To keep from caching AJAX requests add a pseudo timestamp to the end of the URL you request. Commented Nov 5, 2014 at 17:46
  • 1
    An example of what Jay Blanchard is saying above, is to request the page like this: 'yoursite.com/ajax_script.php?t=1152014105753' where the string of numbers is the current date/time down to the second. This will skip caching and treat it like a new file to your browser. Commented Nov 5, 2014 at 17:58

1 Answer 1

2

I believe this question is a little bit of a duplicate. However, if you want to ensure that caching does not happen on ajax calls, you can append a timestamp to the end of the URL you are hitting.

Example in your JavaScript AJAX prep:

var time_stamp = new Date().getTime();
var myurl = "url_here.php?timestamp=" + time_stamp;
jQuery.get(myurl, /* more parameters */);
/* other relevant code */

Here are some other sources from Google:

Another thing to consider is that it might not be a caching issue. Are you properly clearing any sessions/cookies? (If you are using them)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.