2016-01-18 71 views
0

我在尝试在链接上使用getJSON时通过appcache缓存当前页面时遇到问题。浏览器在线,我已经与navigator.onLine检查,我很确定我的互联网已连接。我尝试过使用AppCache和不使用,看起来只有一个错误,当我使用AppCache,这导致我相信我做错了什么,或者当页面加载时无法发送json请求应用程序缓存?HTML5 appcache导致jquery getJSON返回错误

这里是JSON请求的结果(参见下面的代码)具有和不具有应用程序缓存接通:

随着应用程序缓存(失败): enter image description here

没有应用程序缓存(耶它的工作原理): enter image description here

注意:该请求是跨域的,但我确实在目标上设置了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,所以我想知道为什么请求没有通过。任何帮助将很好,谢谢!

+2

尝试添加'NETWORK:*'部分到您的CACHE MANIFEST – Maxali

+1

@Maxali我不能相信我忘了这么做,它似乎解决了我的问题。如果您将其作为答案张贴,我会接受它作为答案:) – Matt

回答

2

您需要将NETWORK: *部分添加到CACHE MANIFEST。