Prevent browser caching of AJAX call result

后端 未结 21 1533
醉酒成梦
醉酒成梦 2020-11-22 04:47

It looks like if I load dynamic content using $.get(), the result is cached in browser.

Adding some random string in QueryString seems to solve this iss

21条回答
  •  一个人的身影
    2020-11-22 05:04

    Now, it's easy to do it by enabling/disabling cache option in your ajax request, just like this

    $(function () {
        var url = 'your url goes here';
        $('#ajaxButton').click(function (e) {
            $.ajax({
                url: url,
                data: {
                    test: 'value'
                },
                    cache: true, //cache enabled, false to reverse
                    complete: doSomething
                });
            });
        });
        //ToDo after ajax call finishes
        function doSomething(data) {
            console.log(data);
        }
    });
    

提交回复
热议问题