HTML5 appcache 导致 jquery getJSON 到 return 错误

HTML5 appcache causing jquery getJSON to return error

我在 link 上尝试使用 getJSON 时遇到问题,而当前页面是通过 appcache 缓存的。浏览器在线,我已经用 navigator.onLine 检查过,我很确定我的互联网已连接。我已经尝试过使用 AppCache 和不使用 AppCache,似乎只有当我使用 AppCache 时出现错误,这让我相信我做错了什么或者你无法发送 json 请求时页面加载了应用程序缓存?

这是 json 请求(见下面的代码)打开和不打开 appcache 的结果:

使用 AppCache(失败):

没有 AppCache(是的,它可以工作):

注意: 请求是跨域的,尽管我在目标上设置了 Access-Control-Allow-Origin

我的代码

Service.appcache

CACHE MANIFEST
plugins/bootstrap-switch.min.css
plugins/bootstrap-timepicker.min.css
plugins/bootstrap-datepicker.css
plugins/jquery.min.js
plugins/bootstrap-switch.min.js
plugins/bootstrap-datepicker.min.js
plugins/bootstrap-timepicker.min.js
plugins/Dexie.min.js
plugins/jSignature.min.js
plugins/bootstrap.min.css
plugins/select2.min.css
plugins/select2.full.min.js
fonts/glyphicons-halflings-regular.woff
fonts/glyphicons-halflings-regular.ttf
fonts/glyphicons-halflings-regular.woff2


SETTINGS:
prefer-online

index.php

<html manifest="/service.appcache"> 
....
$( document ).on( 'click', '#getdbdata', function () 
{
    if(navigator.onLine == true) 
    {
        $.getJSON( "http://example.com/getdata?apikey="+apikey, function( data ) 
        {
            console.log(data);
            alert( "Database has been updated!" );
        })
        .fail(function() {
            alert( "Could not update the database at this time!" );
        })

    }
});
....
</html>

我不太了解appcache,所以我想知道为什么请求没有通过。任何帮助都会很好,谢谢!

您需要将 NETWORK: * 部分添加到缓存清单中。