感谢这篇文章,我能够解决移动 safari 将缓存 ajax POST 请求的问题。添加“headers: {'Cache-Control': 'no-cache'}”似乎对我在移动 safari 中的页面起到了作用。
但是,当我通过移动 safari webapp 访问我的网站时,ajax 请求仍然被缓存。我一直无法找到解决方案,所以我想我会在这里发布。除了添加上面提到的标头之外,我还尝试添加“cache: false”以及放置“url:'/ajax_url?v='+time”。似乎没有任何效果。
为什么移动 safari 与 webapp 的行为不同?我该如何解决这个问题?
编辑:
忘记我的代码了。这里是:
function send_ajax(my_data,refresh){
var now = new Date();
var n = now.getTime();
$.ajax({
url: "/ajax_page?time=" + n,
type: "POST",
headers: {"cache-control": "no-cache"},
data: my_data,
dataType: 'json'
})
.fail( function (jqXHR, textStatus, errorThrown){
})
.done(function(data){ // refresh the page after we get the results
if(refresh=='true'){
var pathArray = window.location.pathname.split('/');
window.location.href = '/' + pathArray[1];
}
});
}
send_ajax({'my_checkbox': $('#my_checkbox').is(':checked') },'true');