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

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


当前回答

当我在样式表中嵌入web字体时,我已经嵌入了所有类型的字体以及woff, woff2, ttf。最近我注意到Chrome取消请求ttf和woff时,woff2是存在的。我现在使用Chrome版本66.0.3359.181,但我不确定Chrome什么时候开始取消额外的字体类型。

其他回答

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

创建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

从严格的Angular角度来看:

当你不能在代码层面上正确地中断时,就会发生这种情况。

假设request1出来了,它的响应也是, 在那之后,嵌套的request2也出去了,它的响应也来了,我们直接打破了循环,没有正确地破坏request1的订阅,

在那个时候,它发生了

另一件要注意的事情可能是AdBlock扩展,或一般的扩展。

但“很多”人有AdBlock....

为了排除扩展,以隐身方式打开一个新标签,确保你想测试的扩展“允许隐身”是关闭的。

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

我们有这个问题有标签<按钮>的形式,这是应该从js发送ajax请求。但是这个请求被取消了,由于浏览器,它会自动发送表单内的任何点击按钮。

因此,如果你真的想在页面上使用button而不是常规的div或span,并且你想发送form throw js -你应该设置一个带有preventDefault函数的监听器。

e.g.

$('button').on('click', function(e){

    e.preventDefault();

    //do ajax
    $.ajax({

     ...
    });

})