2017-10-15 139 views
1

我通過Ajax發送訂單到電子郵件。所有瀏覽器都能正常工作接受Safari,因爲我看到它緩存了請求和響應中的數據。我怎麼能解決這個問題。因爲在Safari中表單隻在清除緩存後才發送。防止緩存Ajax

$('#form-constructor').submit(function() { 
     var form_data = $(this).serialize(); 

     $.ajax({ 
     type: "POST", 
     url: "data/constructor.php", 
     data: form_data, 
     cache: false, 
     success: function() { 
       document.cookie.split(";").forEach(function(c) { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); }); 
       window.onpageshow = function (event) { 
if (event.persisted) {window.location.reload();}}; 
+0

[jQuery的AJAX調用結果防止瀏覽器緩存(可能的重複https://stackoverflow.com/questions/367786/prevent-browser-caching-of -jquery-ajax-call-result) –

回答

2

在你的php頁面中使用隨機數字。與此婁代碼「URL」的值更改爲:

url: "data/constructor.php?rand=" + Math.random(), 
+0

不幸的是,這種方法在Safari上不起作用。與Chrome一切都很好,但野生動物園 –

+0

我想你可以從這個鏈接找出問題:[在safari數學隨機不是隨機](https://stackoverflow.com/questions/7675557/in-safari-and-i -think-也-IE7-和-8-數學隨機是-不隨機) – fatih