I'm making a couple $.post
calls in my script, and I'd like to use $.ajaxSetup
to handle cache control.
function function1()
$.ajaxSetup({
type: 'POST',
headers: { "cache-control": "no-cache", "pragma-cache": "no-cache" }
});
$.post('getLists.php', {user: authUser, token: authToken}, function(data){
$('nav a[class!=btnNewList]').remove();
$.each(data.objects, function(index, element){
$('nav').append('<a href="#" data-list-id="'+element.id+'">'+element.title+'</a>');
});
$('nav').children('a:first-child').next('a').addClass('selected');
getClipsForList($('nav').children('a:first-child').next('a').attr('data-list-id'));
}, 'json');
function function2(){
$.ajaxSetup({
type: 'POST',
headers: { "cache-control": "public", "pragma-cache": "public" }
});
$.post('getClips.php', {user: authUser, token: authToken}, function(data){
spinner.stop();
$.each(data.objects, function(index, element){
if(element.list == '/api/lists/'+id+'/'){
$('#clips ul').append('<li data-url="'+element.url+'">'+truncate(element.title, 100)+'</li>');
}
});
},'json');
}
I'm building a mobile web app, and I noticed it was caching my JSON responses, so I did some research and found the $.ajaxSetup
solution. It worked great, but it seems now, regardless of what I set the cache control property to, it's always caching now. I'd like to cache only certain $.post calls. Any way to do this?
I've tried using $.ajax
instead of $.post
for the function I want cached data and setting the global property to false, but it still won't cache.
This was fixed by simply using $.ajax for each call and explicity settings the headers on a per call basis, rather than trying to use a global setup with $.post.