How to disable browser cache?

2019-05-23 13:44发布

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

5条回答
看我几分像从前
2楼-- · 2019-05-23 14:22

Insert following lines within "head" tag as follows,

<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
查看更多
Deceive 欺骗
3楼-- · 2019-05-23 14:30

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.

查看更多
再贱就再见
4楼-- · 2019-05-23 14:34

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.

查看更多
劫难
5楼-- · 2019-05-23 14:36

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.

查看更多
狗以群分
6楼-- · 2019-05-23 14:45

Use:

Cntl/Cmd + Shift + R

To ignore the cache in Chrome.

查看更多
登录 后发表回答