iOS 6 上的 Safari 是否緩存 $.ajax 結果? - Is Safari on iOS 6 caching $.ajax results?

問題:

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章