問題:
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
手動添加到標題中,但沒有幫助。 web
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: 例如,假設有一個相似如下內容的函數: ajax
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. 必定要趕忙Apple加快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: 咱們發現的解決方法是將函數簽名修改成以下形式: app
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. 這能夠解決此問題。 I hope this helps some other poor soul who spends 15 hours on this issue like I did! 但願這對其餘像我同樣在這個問題上花費15個小時的可憐人有所幫助! ide
解決方案:
參考一: https://stackoom.com/question/qTc9/iOS-上的Safari是否緩存-ajax結果參考二: https://oldbug.net/q/qTc9/Is-Safari-on-iOS-6-caching-ajax-results