Reputation: 20406
I'm using jquery ajax, how to clear the cache of the ajax result?
Upvotes: 1
Views: 17094
Reputation: 11
<script>
var counter = 0;
var counterValue = 0;
function submitForm()
{
counter = counter + 1;
counterValue = counter;
var params = $("#DetailForm").formSerialize();
$("#DetailViewDiv").load("./shopmart/priceDetail.jsp?counterValue="+counter+"&"+params,
function(){$("#PriceTagDiv").show();});
}
</script>
You add a counter for every request. Ajax will cache the call but as the counter increments everytime, the params to load jsp will become different.
Upvotes: 1
Reputation: 256
If you want to bypass the cache you can add some random argument to the url:
var url = 'http://example.com/ajax?' + (new Date()).getTime();
Upvotes: 5
Reputation: 2524
Are you looking for $.ajax cache option? http://docs.jquery.com/Ajax/jQuery.ajax#options
Upvotes: 7
Reputation: 321578
You can't actually clear the cache as it's controlled by the browser, but you can ask for the next request not to be cached by adding cache: false
to your options.
$.get('/callback/', {cache: false});
Upvotes: 0