問題:
Since the upgrade to iOS 6, we are seeing Safari's web view take the liberty of caching $.ajax
calls.自從升級到 iOS 6 以來,我們看到 Safari 的 web 視圖冒昧地緩存$.ajax
調用。 This is in the context of a PhoneGap application so it is using the Safari WebView.這是在 PhoneGap 應用程序的上下文中,因此它使用的是 Safari WebView。 Our $.ajax
calls are POST
methods and we have cache set to false {cache:false}
, but still this is happening.我們的$.ajax
調用是POST
方法,我們將緩存設置爲 false {cache:false}
,但這種情況仍在發生。 We tried manually adding a TimeStamp
to the headers but it did not help.我們嘗試將TimeStamp
手動添加到標題中,但沒有幫助。
We did more research and found that Safari is only returning cached results for web services that have a function signature that is static and does not change from call to call.我們進行了更多研究,發現 Safari 僅返回具有靜態函數簽名且不會隨調用而變化的 Web 服務的緩存結果。 For instance, imagine a function called something like:例如,想象一個名爲的函數,如下所示:
getNewRecordID(intRecordType)
This function receives the same input parameters over and over again, but the data it returns should be different every time.這個函數一遍遍地接收相同的輸入參數,但是每次返回的數據應該都不一樣。
Must be in Apple's haste to make iOS 6 zip along impressively they got too happy with the cache settings.一定是蘋果公司急於讓 iOS 6 快速升級,他們對緩存設置太滿意了。 Has anyone else seen this behavior on iOS 6?有沒有其他人在 iOS 6 上看到過這種行爲? If so, what exactly is causing it?如果是這樣,究竟是什麼原因造成的?
The workaround that we found was to modify the function signature to be something like this:我們發現的解決方法是將函數簽名修改爲如下所示:
getNewRecordID(intRecordType, strTimestamp)
and then always pass in a TimeStamp
parameter as well, and just discard that value on the server side.然後始終傳遞一個TimeStamp
參數,並在服務器端丟棄該值。 This works around the issue.這解決了這個問題。
解決方案:
參考一: https://en.stackoom.com/question/qTc9參考二: https://stackoom.com/question/qTc9