为什么我的 XHR 的 statusText 是空的?

2022-01-15 00:00:00 http xmlhttprequest javascript

当我在我们的生产系统上执行 XHR 时,响应中的 statusText 将是一个空字符串.但是,在我们的开发系统中,statusText 会正确反映状态.

When I perform an XHR on our production system, the statusText in the response will be an empty string. However, on our development system, the statusText will reflect the status correctly.

根据 XMLHttpRequest.statusText<的文档/code>,它只能在处理请求时为空.但是,我在 onload 处理程序中看到了这种行为.

According to the documentation for XMLHttpRequest.statusText, it should only be empty while the request is being processed. However, I am seeing this behavior in the onload handler.

此外,这种行为只能在 Chrome 和 Edge 中观察到.Firefox 将显示正确的文本.

Additionally, this behavior can only be observed in Chrome and Edge. Firefox will display the correct text.

那么,statusText的内容究竟是如何确定的呢?

So, how is the content of the statusText actually determined?

推荐答案

可能是因为一台服务器使用 HTTP/2,而另一台没有.HTTP/2 不再有原因短语.

It might be because one server uses HTTP/2, while the other does not. HTTP/2 doesn't have reason phrases anymore.

相关文章