【问题标题】:update offline cache w/ajax使用 ajax 更新离线缓存
【发布时间】:2013-09-17 17:16:25
【问题描述】:

我有一个使用 Ajax 获取内容的网站。

是否可以这样做:

1) 在第一次请求时获取一些数据并存储在离线缓存中(我知道这个可以做到)

2) 使用 ajax 获取其他数据并将其添加到离线缓存存储中,以便下次用户在没有工作互联网连接的情况下将浏览器触发到我的 url 时,将显示最近获取的数据?

【问题讨论】:

    标签: jquery ajax html offline-caching


    【解决方案1】:

    是的,有可能。

    你可以这样做。

    • 首先读取缓存中的内容。 (存储的内容在键值对中)

    你可以这样做

    var storeObj = window.localStorage;
    var string = storeObj.getItem(storeKey);
    

    // 这将是字符串

    如果需要,将其解析为 json。

                    json = JSON.parse(string);
    

    * 现在将结果附加为字符串或 json。

    // if by json
    json["item"] = "newvalue";
    
    • 现在按键清除存储

      storeObj.removeItem(storeKey);
      
    • 现在将这个新的 json 存回缓存

      storeObj.setItem(storeKey, JSON.stringify(json));
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-30
      • 2018-03-28
      相关资源
      最近更新 更多