Javascript 无法清除临时存储

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31358446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 06:35:42  来源:igfitidea点击:

Failed to clear temp storage

javascriptjquery

提问by Sahil Kore

Failed to clear temp storage: It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources. SecurityError

无法清除临时存储:确定在 Web 应用程序中访问某些文件不安全,或者对文件资源进行了过多调用。安全错误

I'm getting this error in console. I have a script name script.js which makes ajax calls to retrieve data from php.

我在控制台中收到此错误。我有一个脚本名称 script.js,它进行 ajax 调用以从 php 检索数据。

Any idea why?

知道为什么吗?

Here's my jQuery script

这是我的 jQuery 脚本

$(document).ready(function() {

  var loading = false;
  var docHeight = $(window).height();

  $('.timeline').css({minHeight: docHeight});

  function get_tl_post() {

    if (loading==false) {

      loading = true;

      $.ajax({
        type:"POST",
        url:"timeline.php",
        data:"data=instagram",
        beforeSend:function(){
           $('.loader').fadeIn("slow");
        },
        complete:function(){
          loading = false;
          $('.loader').fadeOut("slow");
        },
        success:function(data) {
          if(data=="error")
          {
            get_tl_post();
          }
          $(data).hide().appendTo(".timeline").fadeIn(1000); 
        }
      });
    }
  }

  $(window).scroll(function(){
    if ($(window).scrollTop() == $(document).height() - $(window).height()) {
      get_tl_post();
    }
  });
});

回答by Tarandeep Singh

This is Due to Network Mapping of your resources.

这是由于您的资源的网络映射。

In other words, you might have added workspace folderin your chrome dev tools. Now when you are trying to make changes in some files it makes the Request to the File-System. This works fine for a while. However in some scenarios you remove your network mapping.

换句话说,您可能在 chrome 开发工具中添加了工作区文件夹。现在,当您尝试对某些文件进行更改时,它会向文件系统发出请求。这可以正常工作一段时间。但是,在某些情况下,您会删除网络映射。

Then when you trying to open that web page on the browser, it might or might not ask for remapping of network resources and still try to update the File System. And that's when you get this error. There is nothing wrong with your script.

然后,当您尝试在浏览器上打开该网页时,它可能会或可能不会要求重新映射网络资源,但仍会尝试更新文件系统。这就是您收到此错误的时候。你的脚本没有任何问题。

Now the only solution to this could be Removing cache, then restarting System. If the problem still persist, you can simply re install chrome and this should be fixed.

现在唯一的解决方案可能是删除缓存,然后重新启动系统。如果问题仍然存在,您只需重新安装 chrome 即可解决此问题。

Moreover, sometimes network mapping can cause several other issues as well. For example, making the CSS file size to whooping 75MB or above. So you have to take precautions when playing with network mapping.

此外,有时网络映射也会导致其他几个问题。例如,使 CSS 文件大小达到 75MB 或以上。所以你在玩网络映射时必须采取预防措施。

Optionally if you are on Mac... or Even on Windows and have sh commands available.

或者,如果您在 Mac 上...或者甚至在 Windows 上并且有可用的 sh 命令。

sudo find / -type f -size +50000k -exec ls -lh {} \; | awk '{ print  ": "  }'

Hit this in your Terminal to find out the culprit individual file which is over 50MB. you could then remove them.

在您的终端中点击此按钮以找出超过 50MB 的罪魁祸首个人文件。然后你可以删除它们。

Note : What the above command does it, it will find all the individual files which are more than 50MB and print them on your terminal one by one.

注意:上面的命令是做什么的,它会找到所有超过 50MB 的单个文件,并将它们一一打印在您的终端上。

回答by Jaylen

If I was to guess I would say your timeline.phpscript is always returning "error" so you are making too many calls recursively and the browser blocks them.

如果我猜测我会说您的timeline.php脚本总是返回“错误”,因此您递归地进行了太多调用并且浏览器阻止了它们。

Try to eliminate the recursive function call and see if that will fix the problem.

尝试消除递归函数调用,看看是否能解决问题。

Remove the following 3 lines and try again:

删除以下 3 行并重试:

if (data == "error")
{
    get_tl_post();
}

回答by Nick Louloudakis

If your ajax call fails for some reason, this could lead to too many recursive calls of the get_tl_post();.

如果您的 ajax 调用由于某种原因失败,这可能会导致get_tl_post();.

I suggest that you use the errorproperty for error handling, and to avoid situations of recursively calling your function. An idea could be to set a policy like "if the request failed/data are with errors, wait for an amount of time, then retry. If X retries are made, then show an error code and stop requesting".

我建议您使用该error属性进行错误处理,并避免递归调用您的函数的情况。一个想法可能是设置一个策略,例如“如果请求失败/数据有错误,请等待一段时间,然后重试。如果进行了 X 次重试,则显示错误代码并停止请求”。

Below is an example of untestedcode, in order to show you the idea:

下面是一个未经测试的代码示例,以向您展示这个想法:

var attempts = 0;
$.ajax({
  //Rest of properties
  success: function(data) {

    if(data == "error") {
      if(attempts < 3) {
        setTimeout(function(){
          get_tl_post();
          ++attempts;
        }, 2000);
      } else {
        //output failure here.
      }

    }

    //Rest of code....
  }
});