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

前端 未结 30 1673
温柔的废话
温柔的废话 2020-11-22 11:13

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

\"Canceled

相关标签:
30条回答
  • 2020-11-22 11:35

    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>
    
    0 讨论(0)
  • 2020-11-22 11:35

    For my case, I had an anchor with click event like

    <a href="" onclick="somemethod($index, hour, $event)">
    

    Inside click event I had some network call, Chrome cancelling the request. The anchor has href with "" means, it reloads the page and the same time it has click event with network call that gets cancelled. Whenever i replace the href with void like

    <a href="javascript:void(0)" onclick="somemethod($index, hour, $event)">
    

    The problem went away!

    0 讨论(0)
  • 2020-11-22 11:37

    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.

    0 讨论(0)
  • 2020-11-22 11:37

    I had faced the same issue, somewhere deep in our code we had this pseudocode:

    • create an iframe
    • onload of iframe submit a form

    • After 2 seconds, remove the iframe

    thus, when the server takes more than 2 seconds to respond the iframe to which the server was writing the response to, was removed, but the response was still to be written , but there was no iframe to write , thus chrome cancelled the request, thus to avoid this I made sure that the iframe is removed only after the response is over, or you can change the target to "_blank". Thus one of the reason is: when the resource(iframe in my case) that you are writing something in, is removed or deleted before you stop writing to it, the request will be cancelled

    0 讨论(0)
  • 2020-11-22 11:38

    A cancelled request happened to me when redirecting between secure and non-secure pages on separate domains within an iframe. The redirected request showed in dev tools as a "cancelled" request.

    I have a page with an iframe containing a form hosted by my payment gateway. When the form in the iframe was submitted, the payment gateway would redirect back to a URL on my server. The redirect recently stopped working and ended up as a "cancelled" request instead.

    It seems that Chrome (I was using Windows 7 Chrome 30.0.1599.101) no longer allowed a redirect within the iframe to go to a non-secure page on a separate domain. To fix it, I just made sure any redirected requests in the iframe were always sent to secure URLs.

    When I created a simpler test page with only an iframe, there was a warning in the console (which I had previous missed or maybe didn't show up):

    [Blocked] The page at https://mydomain.com/Payment/EnterDetails ran insecure content from http://mydomain.com/Payment/Success
    

    The redirect turned into a cancelled request in Chrome on PC, Mac and Android. I don't know if it is specific to my website setup (SagePay Low Profile) or if something has changed in Chrome.

    0 讨论(0)
  • 2020-11-22 11:38

    I had the exact same thing with two CSS files that were stored in another folder outside my main css folder. I'm using Expression Engine and found that the issue was in the rules in my htaccess file. I just added the folder to one of my conditions and it fixed it. Here's an example:

    RewriteCond %{REQUEST_URI} !(images|css|js|new_folder|favicon.ico)
    

    So it might be worth you checking your htaccess file for any potential conflicts

    0 讨论(0)
提交回复
热议问题