javascript XHR 请求虽然看起来成功,但表示被取消

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8302579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 02:59:06  来源:igfitidea点击:

XHR request is denoted as being cancelled although it seems to be successful

javascriptjqueryajaxgoogle-chrome-devtools

提问by Naftali aka Neal

This is not really an issue, because the code works, butI am just curious as to why it happens.

这不是真正的问题,因为代码有效,我只是好奇它为什么会发生。

I have the following jQuery code for an ajax post:

我有以下 jQuery 代码用于 ajax 帖子:

$.post('./add_fee_row/<?php echo $date; ?>',post, function(data){ ... });

It all works fine and dandy.

一切正常,花花公子。

However in the Chrome Console it says: what is going on here?

但是在 Chrome 控制台中它说: 这里发生了什么?

Why does it say cancelled?

为什么说取消了?

Everything happened as if the post was successful. Why does it say that?

一切就好像帖子成功一样发生了。为什么这么说?

(the php server code is available if needed)

(如果需要,可以使用php服务器代码)

I am using Google Chrome version: 17.0.942.0

我使用的是谷歌浏览器版本:17.0.942.0

采纳答案by vsevik

There was a bug in Chrome DevTools, it is already fixed: http://code.google.com/p/chromium/issues/detail?id=104920

Chrome DevTools 中存在一个错误,已修复:http: //code.google.com/p/chromium/issues/detail?id=104920

回答by Kemal Can Kara

it may happen when Chrome sees that the actual data doesn't match the headers.

当 Chrome 发现实际数据与标题不匹配时,可能会发生这种情况。

If you return your answer with header type added, it shouldnt say canceled (Content-type: text/plain. for example)

如果您返回添加了标题类型的答案,则不应说已取消(例如,内容类型:文本/纯文本)

You can check them by looking Event tabs - response headers.

您可以通过查看事件选项卡 - 响应标头来检查它们。