Is Safari on iOS 6 caching $.ajax results?

前端 未结 25 971
轮回少年
轮回少年 2020-11-22 09:34

Since the upgrade to iOS 6, we are seeing Safari\'s web view take the liberty of caching $.ajax calls. This is in the context of a PhoneGap application so it is

25条回答
  •  抹茶落季
    2020-11-22 09:58

    I was able to fix my problem by using a combination of $.ajaxSetup and appending a timestamp to the url of my post (not to the post parameters/body). This based on the recommendations of previous answers

    $(document).ready(function(){
        $.ajaxSetup({ type:'POST', headers: {"cache-control","no-cache"}});
    
        $('#myForm').submit(function() {
            var data = $('#myForm').serialize();
            var now = new Date();
            var n = now.getTime();
            $.ajax({
                type: 'POST',
                url: 'myendpoint.cfc?method=login&time='+n,
                data: data,
                success: function(results){
                    if(results.success) {
                        window.location = 'app.cfm';
                    } else {
                        console.log(results);
                        alert('login failed');
                    }
                }
            });
        });
    });
    

提交回复
热议问题