javascript - 缓存 list 导致 $.getJSON 停止

标签 javascript jquery html mobile offline-mode

我正在使用 HTML5、Javascript、jQuery Mobile 和离线存储开发移动应用。

我有一个 wep 应用程序,它向移动应用程序(在同一域上)提供 JSON 对象数组。它获取 JSON 对象,将它们存储在 websql 数据库中,然后使用它们创建一个可以单击的无序列表...

这个想法是,当设备处于离线模式时,我将从离线数据库中提取数据并绕过从 Web 应用程序获取 JSON,然后当设备下次在线时,它可以获得数据的新副本。

我已经到了创建cache.manifest 文件的部分了。基本上看起来像这样:

CACHE MANIFEST

CACHE:
index.html
app.html

NETWORK:
http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js
http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css
http://code.jquery.com/jquery-1.4.3.min.js
js/data.js
js/script.js

但是一旦我添加

<html  manifest="cache.manifest">

并重新加载我的 $.getJSON 停止的页面(可以在 data.js 中找到)。该文件中的其他 JS 代码似乎执行但该函数。

这是在加载时执行的函数:

function getAppointments(){
// Update appointments ONLY when online
if(navigator.onLine = true){
    console.log('Application Online.')

    // create appointments table
    createAppTable();
    $.getJSON("http://site.com/OptiQuoteApp/index.php/appointments/download/", function(data) {
        $.each(data,function()
        {
            // Save appointments in database
            updateAppointments(this.quote_id, this.start_date, this.reference, this.first_name+' '+this.last_name, this.comment);
        });
         getAppointmentsList();
    });
}else{
    console.log('Application Offline.')

}
getAppointmentsList();

}

注意。我知道它说的是 site.com(出于安全考虑...)

脚本到达createAppTable();然后就没有了。

有人知道吗?

比利

非常感谢

最佳答案

尝试在 list 文件的“网络:”下添加 *。这样,任何未专门缓存的内容都会从您的网站中提取。

NETWORK:
http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js
http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css
http://code.jquery.com/jquery-1.4.3.min.js
js/data.js
js/script.js
*

关于javascript - 缓存 list 导致 $.getJSON 停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6736275/

相关文章:

javascript - 在 Angular 中使用 `fetch`

javascript - 查找所有表单值并提交

jquery - 用最后一个逗号分割字符串

javascript - 页面加载时如何调用 AnimateScroll 插件?

html - header 不允许 <span> 在同一行中对齐

javascript - jQuery + 安卓。将功能(Touchstart、touchmove)应用于实时加载的内容

mysql - ASP.NET如何在div中显示sqldatasource行?

javascript - 打开 id 以特定单词开头的树节点

javascript - Jquery/CSS 动画性能

javascript - 使用数据切换操作 html 进行分页