什么会导致页面被取消?我有一个Chrome开发者工具的截图。
这种情况经常发生,但不是每次都发生。似乎一旦缓存了一些其他资源,页面刷新就会加载LeftPane.aspx。真正奇怪的是,这只发生在谷歌Chrome浏览器中,而不是ie8。知道为什么Chrome会取消一个请求吗?
什么会导致页面被取消?我有一个Chrome开发者工具的截图。
这种情况经常发生,但不是每次都发生。似乎一旦缓存了一些其他资源,页面刷新就会加载LeftPane.aspx。真正奇怪的是,这只发生在谷歌Chrome浏览器中,而不是ie8。知道为什么Chrome会取消一个请求吗?
当前回答
从严格的Angular角度来看:
当你不能在代码层面上正确地中断时,就会发生这种情况。
假设request1出来了,它的响应也是, 在那之后,嵌套的request2也出去了,它的响应也来了,我们直接打破了循环,没有正确地破坏request1的订阅,
在那个时候,它发生了
其他回答
如果您使用axios,它可以帮助您
// change timeout delay: Instance.defaults.timeout = 2500;
https://github.com/axios/axios#config-order-of-precedence
在这能帮助任何人,我遇到取消状态时,我省略了返回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
});
希望这能帮助到别人。
内容安全策略头为我!你可以通过检查Chrome开发工具控制台来快速排除这种可能性,如果是CSP问题,控制台中会显示错误。在。net中,你可以通过在web中添加头部来解决这个问题。配置文件或代码。
拒绝将表单数据发送到“https://www.mysite.mydomain/”,因为它违反了以下内容安全政策指令:“表单-操作'自我' *。otherdomain www.thirdparty.co.uk”。
这是网络。以上错误的配置修正:
< cspConfiguration > < directives > <指示 < /指令> < / directives > < / cspConfiguration >
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);
这解决了间歇性取消请求的问题。
当我通过JavaScript重定向时,我在Chrome中得到了这个错误:
<script>
window.location.href = "devhost:88/somepage";
</script>
如你所见,我忘记了'http://'.在我添加它之后,它起作用了。