Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Chrome扩展-缓存JSON文件1天_Javascript_Jquery_Json_Google Chrome_Google Chrome Extension - Fatal编程技术网

Javascript Chrome扩展-缓存JSON文件1天

Javascript Chrome扩展-缓存JSON文件1天,javascript,jquery,json,google-chrome,google-chrome-extension,Javascript,Jquery,Json,Google Chrome,Google Chrome Extension,我的Chrome扩展根据JSON白名单决定是否激活。当前使用下面的函数检索此文件。我想做的是,将文件存储一段时间,比如说1天,即使浏览器在此期间关闭。最好的方法是什么 请求代码: jQuery.getJSON( "https://www.example.com/whitelist.json" ) //cache this file .done(function( data ) { jQuery.each(data.configs, function(key, val) {

我的Chrome扩展根据JSON白名单决定是否激活。当前使用下面的函数检索此文件。我想做的是,将文件存储一段时间,比如说1天,即使浏览器在此期间关闭。最好的方法是什么

请求代码:

jQuery.getJSON( "https://www.example.com/whitelist.json" ) //cache this file
  .done(function( data ) {
    jQuery.each(data.configs, function(key, val) {
        showMenu();
        return
    })
  })
  .fail(function( jqxhr, textStatus, error ) {
    var err = textStatus + ", " + error;
    console.log( "Request Failed: " + err );
  });

在启动会话之前,使用session_set_cookie_parameters()为会话cookie提供非零生存期,或将session.cookie_生存期设置为非零。 你可以试试这个选项。。
最好的。

您能将其存储在本地存储中,并带有保存到期日期的属性吗?首先检查localStorage,如果它不存在或过期,则可以通过AJAX检索JSON。为什么不将此文件内容保存在
localStorage
中?进行了一些研究,我想localStorage可能非常适合,是的。感谢您的评论。浏览器关闭后,会话将立即关闭,不幸的是,这没有帮助。