How do I prevent a jQuery Ajax request from caching in Internet Explorer?
278
votes
Using POST instead of GET prevents caching. stackoverflow.com/questions/6216234/disable-ajax-caching
– Prashant Gupta
YSlow and Chrome dev tools will warn you if you use POST requests for AJAX - generally GET should be the preferred method unless you really need to POST.
– Pawel Krakowiak
Here is Your answer : disable Cache in IE
– S.Mohamed Mahdi Ahmadian zadeh
6 Answers
533
votes
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...
});
21
votes
12
votes
5
votes
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.
3
votes
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