2

I have an ajax function (in jquery) which update the html. It's ok. Now, When I tap enter in the adress bar (to refresh), my html is not updated (old content). Whereas, when I do cmd + R, my html is always ok.

What is the problem ? Why my content shows old content from the adress bar ?

Edit :

I use Chrome et load() in jQuery

Steffi
  • 6,835
  • 25
  • 78
  • 123
  • What browser are you using? – Srinivas Dec 28 '12 at 11:08
  • What browser are you using? You can't "disable" the browser's cache from a website's code... you should just do `cmd + R` or the even harder refresh of `cmd + shift + R` if you need to reload everything. – cereallarceny Dec 28 '12 at 11:09
  • May be this link be of use http://stackoverflow.com/questions/168963/stop-jquery-load-response-from-being-cached – jsist Dec 28 '12 at 11:12
  • What kind of server-side script you're using ? – Shehabic Dec 28 '12 at 11:16
  • There are tons of articles about Google Chrome's Cache. Have you tried to Google for `disable google chrome cache ajax`? Anyway, why you want to disable cache? For development only? I recommend you to disable this in your browser. – Ron van der Heijden Dec 28 '12 at 11:17

5 Answers5

5

If you have problem with caching in the browser itself, you need to set header to prevent caching in your Server Side's Code (e.g. Php, Java, Python .....etc).

But if you want to avoid caching in your Ajax Function use this Code:

 $.ajax({
              url : scriptUrl,
              type : "get", // or 'post'
              cache : false, // This is to avoid Cache in Ajax Requests
              // .........................etc
});

Notice: Give more details on your question to get a sharper answer.

Shehabic
  • 6,787
  • 9
  • 52
  • 93
4

Insert following lines within "head" tag as follows,

<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
HILARUDEEN S ALLAUDEEN
  • 1,722
  • 1
  • 18
  • 33
1

Use:

Cntl/Cmd + Shift + R

To ignore the cache in Chrome.

Tom Walters
  • 15,366
  • 7
  • 57
  • 74
1

Providing more details will help. I think your ajax code is not working. May be it is fetching the data but not updating the page proeprly. Try checking th error console if you are in firefox. It should show you any errors if you are getting in updating the content.

Try using fiddler to find out what you are actually fetching using ajax. There are many things which can happen here and will make it fail.

Murtuza Kabul
  • 6,438
  • 6
  • 27
  • 34
  • My ajax code is working because it returns me the good content without refresh page. And it returns me the good content with `cmd + R`. The problem is when I tap enter from the address bar, it shows the old content. – Steffi Dec 28 '12 at 11:12
  • when you press cmd+r the entire page is refreshed and not just the ajax code so you will get the content. However, if the ajax is not working properly, only the ajax part will not work. I still suggest that you check the function using fiddler and also check if you are getting any javascript error – Murtuza Kabul Dec 28 '12 at 11:13
0

Use this, after jQuery has been loaded

jQuery.ajaxSetup({ cache: false });

For more information, check the documentation for jQuery.ajaxSetup

This function uses the same options that are passed to jQuery.ajax() method.

Please note that this will disable caching for all jQuery ajax requests.

Vishal
  • 2,030
  • 22
  • 27