AJAX为canceled

Posted coolgame

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AJAX为canceled相关的知识,希望对你有一定的参考价值。

https://stackoverflow.com/questions/12009423/what-does-status-canceled-for-a-resource-mean-in-chrome-developer-tools

 

AJAX默认的是异步模式,经过观察,频繁请求,之前的某个请求超时会引起这个问题。

改成同步即可。

 

 

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>
  • 2
    This saved me, was the problem in my case where I used angular\'s ng-click on a button with type="submit" and then did some networking in the called function. Chrome kept canceling that request...– Robin Jan 6 \'15 at 13:36
  • 1
    Unfortunately it does not work for me. Any other hints? – Krzysztof Jan 13 \'16 at 10:10
  •  
    Vaov saved me too! For an angular ng-click event I had nested $http requests and second one was being canceled. After setting the prevent default line it started working again, thanks. – Bahadir Tasdemir Sep 20 \'16 at 15:03
  •  
    Thanks for this. I knew it was not CORS or a DOM issue. Perhaps @whamma could update their answer to include this as possible cause for completeness :) – glidester Oct 20 \'17 at 11:15
     
     
     

以上是关于AJAX为canceled的主要内容,如果未能解决你的问题,请参考以下文章

[RxJS] Implement RxJS `switchMap` by Canceling Inner Subscriptions as Values are Passed Through(代码片段

一次ajax请求导致status为canceled的原因

html PHP代码片段: - AJAX基本示例:此代码演示了使用PHP和JavaScript实现的基本AJAX功能。

AJAX相关JS代码片段和部分浏览器模型

Javascript代码片段在drupal中不起作用

MFP 8.0 WLAuthorizationManager.obtainAccessToken 返回错误,错误代码为 CHALLENGE_HANDLING_CANCELED