I have the following Ajax code using POST:
<script type="text/javascript">
$('#consultdate').change(function() {
consultdate = $('#consultdate').val();
userid= '<?php echo $user_id;?>';
cat = '<?php echo $category;?>';
//alert(consultdate);
$.ajax({
type: "POST",
url: 'qry/date-time_qry.php',
headers: {
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0'
},
data: {consultdate : consultdate, userid : userid, cat : cat },
success: function(data)
{
alert(data);
$('input#consulttime').timepicker({ 'disableTimeRanges':JSON.parse(data)});
},
error : function() {
alert("error while loading data");
}
});
});
</script>
In my server side code too, i placed the prevent cache headers.
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
The ajax call is tied to jQuery Datepicker. If i select one date and then another date it is displaying the old data which seems to be a data cache issue. I also tried cache: false
without any result. It is persisting. Any solution other than using GET and Math.random() etc...??
I tried the solutions in the following link: Prevent browser caching of jQuery AJAX call result