什么会导致页面被取消?我有一个Chrome开发者工具的截图。

这种情况经常发生,但不是每次都发生。似乎一旦缓存了一些其他资源,页面刷新就会加载LeftPane.aspx。真正奇怪的是,这只发生在谷歌Chrome浏览器中,而不是ie8。知道为什么Chrome会取消一个请求吗?


当前回答

对于任何来自LoopbackJS并试图使用图表示例中提供的自定义流方法的人。我使用PersistedModel得到这个错误,切换到基本模型修复了我的事件源状态取消的问题。

同样,这是专门针对环回api的。既然这是谷歌上的顶级答案,我想我应该把这个放在混合答案中。

其他回答

请求可能已经被跟踪保护插件阻止了。

我也遇到过同样的问题,在我们的代码深处,我们有这样的伪代码:

创建iframe 加载iframe提交一个表单 2秒后,移除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

status= cancelled也可能发生在JavaScript事件的ajax请求上:

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

<button id="call_ajax">call</button> 

事件成功发送请求,但随后被取消(但由服务器处理)。原因是,元素在单击事件时提交表单,无论您是否对同一单击事件发出任何ajax请求。

为了防止请求被取消,JavaScript event.preventDefault();必须被称为:

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

如果你使用了一些基于可观察对象的HTTP请求,比如Angular(2+)中内置的那些请求,那么当可观察对象被取消时,HTTP请求也可以被取消(当你使用RxJS 6 switchMap操作符合并流时很常见的事情)。在大多数情况下,如果您想要完成请求,使用mergeMap操作符就足够了。

内容安全策略头为我!你可以通过检查Chrome开发工具控制台来快速排除这种可能性,如果是CSP问题,控制台中会显示错误。在。net中,你可以通过在web中添加头部来解决这个问题。配置文件或代码。

拒绝将表单数据发送到“https://www.mysite.mydomain/”,因为它违反了以下内容安全政策指令:“表单-操作'自我' *。otherdomain www.thirdparty.co.uk”。

这是网络。以上错误的配置修正:

< cspConfiguration > < directives > <指示 < /指令> < / directives > < / cspConfiguration >