如何防止 jQuery Ajax 请求在 Internet Explorer 中缓存?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4303829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:02:42  来源:igfitidea点击:

How to prevent a jQuery Ajax request from caching in Internet Explorer?

jqueryinternet-explorer

提问by SABU

How do I prevent a jQuery Ajax request from caching in Internet Explorer?

如何防止 jQuery Ajax 请求在 Internet Explorer 中缓存?

回答by Nick Craver

You can disable caching globally using $.ajaxSetup(), for example:

您可以使用 全局禁用缓存$.ajaxSetup(),例如:

$.ajaxSetup({ cache: false });

This appends a timestamp to the querystring when making the request. To turn cache off for a particular $.ajax()call, set cache: falseon it locally, like this:

这会在发出请求时将时间戳附加到查询字符串。要为特定$.ajax()调用关闭缓存,请cache: false在本地设置它,如下所示:

$.ajax({
  cache: false,
  //other options...
});

回答by Koss

If you set unique parameters, then the cache does not work, for example:

如果设置唯一参数,则缓存不起作用,例如:

$.ajax({
    url : "my_url",
    data : {
        'uniq_param' : (new Date()).getTime(),
        //other data
    }});

回答by Koss

Cache-Control: no-cache, no-store

These two header values can be combined to get the required effect on both IE and Firefox

可以将这两个标头值组合起来,在 IE 和 Firefox 上都可以获得所需的效果

回答by DRK

Here is an answer proposal:

这是一个答案建议:

http://www.greenvilleweb.us/how-to-web-design/problem-with-ie-9-caching-ajax-get-request/

http://www.greenvilleweb.us/how-to-web-design/problem-with-ie-9-caching-ajax-get-request/

The idea is to add a parameter to your ajax query containing for example the current date an time, so the browser will not be able to cache it.

这个想法是向您的 ajax 查询添加一个参数,例如包含当前日期和时间,因此浏览器将无法缓存它。

Have a look on the link, it is well explained.

看看链接,它解释得很好。

回答by Fajar A. R

you can define it like this :

你可以这样定义它:

let table = $('.datatable-sales').DataTable({
        processing: true,
        responsive: true,
        serverSide: true,
        ajax: {
            url: "<?php echo site_url("your url"); ?>",
            cache: false,
            type: "POST",
            data: {
                <?php echo your api; ?>,
            }
        }

or like this :

或像这样:

$.get({url: <?php echo json_encode(site_url('your api'))?>, cache: false})

hope it helps

希望能帮助到你

回答by Some_Guy

This is an old post, but if IE is giving you trouble. Change your GET requests to POST and IE will no longer cache them.

这是一个旧帖子,但如果 IE 给你带来麻烦。将您的 GET 请求更改为 POST,IE 将不再缓存它们。

I spent way too much time figuring this out the hard way. Hope it helps.

我花了太多时间以艰难的方式解决这个问题。希望能帮助到你。