【问题标题】:HTML5 appcache causing jquery getJSON to return errorHTML5 appcache 导致 jquery getJSON 返回错误
【发布时间】:2016-04-24 05:06:38
【问题描述】:

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

以下是打开和未打开 appcache 的 json 请求的结果(参见下面的代码):

使用 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: * 部分添加到您的缓存清单中
  • @Maxali 我不敢相信我忘了这样做,它似乎解决了我的问题。如果您将其作为答案发布,我将接受它作为答案:)

标签: jquery html html5-appcache


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-02-22
    • 1970-01-01
    • 2013-01-02
    • 2014-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 2011-02-21
    相关资源
    最近更新 更多