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

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


当前回答

I had the same issue when updating a record. Inside the save() i was prepping the rawdata taken from the form to match the database format (doing a lot of mapping of enums values, etc), and this intermittently cancels the put request. i resolved it by taking out the data prepping from the save() and creating a dedicated dataPrep() method out of it. I turned this dataPrep into async and await all the memory intensive data conversion. I then return the prepped data to the save() method that i could use in the http put client. I made sure i await on dataPrep() before calling the put method:

等待dataToUpdate =等待dataPrep(); http。把(apiUrl dataToUpdate);

这解决了间歇性取消请求的问题。

其他回答

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

这是chrome取消请求的另一个例子,我刚刚遇到过,上面的答案中没有提到。

简单地说 我的android手机上的自签名证书不受信任。

细节 我们正处于开发/调试阶段。url指向自签名主机。代码是这样的:

location.href = 'https://some.host.com/some/path'

Chrome只是默默地取消了请求,没有给像我这样的web开发新手留下任何线索来解决这个问题。一旦我使用android手机下载并安装了证书,问题就消失了。

当我通过JavaScript重定向时,我在Chrome中得到了这个错误:

<script>
    window.location.href = "devhost:88/somepage";
</script>

如你所见,我忘记了'http://'.在我添加它之后,它起作用了。

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

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

e.g.

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

    e.preventDefault();

    //do ajax
    $.ajax({

     ...
    });

})

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>