What does status=canceled for a resource mean in Chrome Developer Tools?

What would cause a page to be canceled? I have a screenshot of the Chrome Developer Tools.

取消资源

This happens often but not every time. It seems like once some other resources are cached, a page refresh will load the LeftPane.aspx. And what's really odd is this only happens in Google Chrome, not Internet Explorer 8. Any ideas why Chrome would cancel a request?


We fought a similar problem where Chrome was canceling requests to load things within frames or iframes, but only intermittently and it seemed dependent on the computer and/or the speed of the internet connection.

This information is a few months out of date, but I built Chromium from scratch, dug through the source to find all the places where requests could get cancelled, and slapped breakpoints on all of them to debug. From memory, the only places where Chrome will cancel a request:

  • The DOM element that caused the request to be made got deleted (ie an IMG is being loaded, but before the load happened, you deleted the IMG node)
  • You did something that made loading the data unnecessary. (ie you started loading a iframe, then changed the src or overwrite the contents)
  • There are lots of requests going to the same server, and a network problem on earlier requests showed that subsequent requests weren't going to work (DNS lookup error, earlier (same) request resulted eg HTTP 400 error code, etc)
  • In our case we finally traced it down to one frame trying to append HTML to another frame, that sometimes happened before the destination frame even loaded. Once you touch the contents of an iframe, it can no longer load the resource into it (how would it know where to put it?) so it cancels the request.


    status=canceled may happen also on ajax requests on JavaScript events:

    <script>
      $("#call_ajax").on("click", function(event){
         $.ajax({
            ...    
         });
      });
    </script>
    
    <button id="call_ajax">call</button> 
    

    The event successfully sends the request, but is is canceled then (but processed by the server). The reason is, the elements submit forms on click events, no matter if you make any ajax requests on the same click event.

    To prevent request from being cancelled, JavaScript event.preventDefault(); have to be called:

    <script>
      $("#call_ajax").on("click", function(event){
         event.preventDefault();
         $.ajax({
            ...    
         });
      });
    </script>
    

    You might want to check the "X-Frame-Options" header tag. If its set to SAMEORIGIN or DENY then the iFrame insertion will be canceled by Chrome (and other browsers) per the spec.

    Also, note that some browsers support the ALLOW-FROM setting but Chrome does not.

    To resolve this, you will need to remove the "X-Frame-Options" header tag. This could leave you open to clickjacking attacks so you will need to decide what the risks are and how to mitigate them.

    链接地址: http://www.djcxy.com/p/36428.html

    上一篇: Javascript文件上传在Chrome中不起作用

    下一篇: 在Chrome开发人员工具中,资源的状态=取消是什么意思?