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

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


当前回答

在这能帮助任何人,我遇到取消状态时,我省略了返回false;在表单中提交。这导致ajax发送之后立即紧跟提交操作,这将覆盖当前页面。代码如下所示,在末尾返回重要的false。

$('form').submit(function() {

    $.validator.unobtrusive.parse($('form'));
    var data = $('form').serialize();
    data.__RequestVerificationToken = $('input[name=__RequestVerificationToken]').val();

    if ($('form').valid()) {
        $.ajax({
            url: this.action,
            type: 'POST',
            data: data,
            success: submitSuccess,
            fail: submitFailed
        });
    }
    return false;       //needed to stop default form submit action
});

希望这能帮助到别人。

其他回答

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

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

我们曾遇到过类似的问题,Chrome会取消在帧内或iframes内加载内容的请求,但只是间歇性的,这似乎取决于计算机和/或互联网连接的速度。

这些信息已经过时几个月了,但是我从头开始构建了Chromium,在源代码中挖掘了所有可以取消请求的地方,并在所有这些地方设置了断点以进行调试。根据记忆,Chrome会取消请求的地方只有:

The DOM element that caused the request to be made got deleted (i.e. an IMG is being loaded, but before the load happened, you deleted the IMG node) You did something that made loading the data unnecessary. (i.e. 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 e.g. HTTP 400 error code, etc)

在我们的例子中,我们最终追踪到一个试图将HTML附加到另一个帧的帧,这有时发生在目标帧加载之前。一旦您接触到iframe的内容,它就不能再将资源加载到其中(它如何知道将资源放在哪里?),因此它会取消请求。

对于我的案例,我有一个锚与点击事件像

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

里面点击事件我有一些网络呼叫,Chrome取消请求。锚有href与""意味着,它重新加载页面,同时它有点击事件与网络调用被取消。每当我用void替换href时

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

问题消失了!

我们遇到(取消)状态的另一个地方是在特定的TLS证书错误配置中。如果一个网站(例如https://www.example.com)配置错误,导致证书不包括www。但有效的https://example.com, chrome将取消此请求,并自动重定向到后者的网站。Firefox则不是这样。

当前有效的示例:https://www.pthree.org/

在我的情况下,它开始出现后chrome 76更新。

由于一些问题在我的JS代码,窗口。位置被多次更新,导致取消先前的请求。 虽然这个问题之前就存在,但chrome在更新到版本76后开始取消请求。