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

JqueryInternet Explorer

Jquery Problem Overview


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

Jquery Solutions


Solution 1 - Jquery

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

$.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: false on it locally, like this:

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

Solution 2 - Jquery

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
	}});

Solution 3 - Jquery

Cache-Control: no-cache, no-store

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

Solution 4 - Jquery

Here is an answer proposal:

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.

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

Solution 5 - Jquery

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

Solution 6 - Jquery

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.

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSABUView Question on Stackoverflow
Solution 1 - JqueryNick CraverView Answer on Stackoverflow
Solution 2 - JqueryKossView Answer on Stackoverflow
Solution 3 - Jqueryuser407283View Answer on Stackoverflow
Solution 4 - JqueryDRKView Answer on Stackoverflow
Solution 5 - JqueryFajar A. RView Answer on Stackoverflow
Solution 6 - JquerySome_GuyView Answer on Stackoverflow