问题标签 [http-status-code-204]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
5938 浏览

javascript - Firefox 控制台在 HTTP 204 响应中抛出“未找到元素”

一切都正常工作,但我无法摆脱 Firefox 控制台中的这个错误:

没有找到元素

我正在向我的 api 发送 HTTP 请求:

我的(django rest framework)api返回一个HTTP_204_NO_CONTENT状态

0 投票
1 回答
8634 浏览

rest - HTTP GET 200 与 204

我们正在设计一个公共 API,并试图通过以下情况找出 GET 的最佳实践:

路径参数:

找到:200 个带有响应正文。
未找到:404。

查询参数:

找到的订单:200 个带有响应正文。

未找到:在这种情况下,这应该是 200 还是 204 甚至是 404?

在我看来,它应该是 200 或 204,因为在这种情况下找到了资源,并且查询参数只是执行过滤效果。但是在这种情况下我们应该返回 200 还是 204?

0 投票
1 回答
1588 浏览

android - 如何从 Android Volley 请求中检测 204 No Content

当我向我的 api 请求时,api 返回 204 - 无内容。但是 volley 不承认这一点并给出 TimeOutError。

我该如何处理?

0 投票
2 回答
1857 浏览

javascript - 如何创建返回 204 的 url

我正在尝试使用 i frame buster buster 代码,但我需要使用 204 url​​。我如何创建给出 204 无内容错误的页面,以便此 iframe buster buster 代码有效

window.top.location = 我想是一个 204 url​​ 那么我如何创建一个

0 投票
1 回答
426 浏览

javascript - 具有 204 响应和回调函数的 Beacon 跟踪图像

几天来,我一直在尝试将我的跟踪像素 JS 功能转换为使用 204“no_content”响应。

我可以很容易地得到这个工作,但我需要能够在之后触发一个回调函数。

一旦返回 204,以下内容似乎永远不会被解雇。

跟踪记录正确,但没有警报或控制台日志消息。这是可能的还是我只是在浪费时间?

编辑 - - -

基于下面的解决方案,这里是最终版本(假设错误和成功都将使用相同的回调。

0 投票
2 回答
996 浏览

html - MSIE/Edge 使用 HTTP HEAD data URLs, then treats 204 response as error?

Background:

Background:

My PHP code handles typical HTTP HEAD requests by sending either an HTTP status 404 response or a 204 response. This seems correct to me, since RFC7231 specifies HTTP status 204 as:

6.3.5. 204 No Content

The 204 (No Content) status code indicates that the server has successfully fulfilled the request and that there is no additional content to send in the response payload body. Metadata in the response header fields refer to the target resource and its selected representation after the requested action was applied...

The 204 response allows a server to indicate that the action has been successfully applied to the target resource, while implying that the user agent does not need to traverse away from its current "document view" (if any)...

A 204 response is terminated by the first empty line after the header fields because it cannot contain a message body...

https://www.rfc-editor.org/rfc/rfc7231#section-6.3.5

Since the user agent is only requesting the headers and not the file itself, 204 seems to fit.

Surprise #1:

When an <object> element has a URL for the data attribute, MSIE/Edge initially makes an HTTP HEAD request in order to determine the content-type via the response headers. While another MS quirk, it makes sense, as it allows the browser to pre-load the needed handlers in advance of receiving the content. When it receives a suitable response to the HEAD request, it will then make an HTTP GET request for the file itself.

Now, this wouldn't have been so much of an issue if it weren't for...

Surprise #2:

When MSIE/Edge receives a 204 response to its HEAD request, it treats it as an error and aborts loading the file.

This was, needless to say, quite frustrating to discover (the process and the discovery itself).

Have I misunderstood the purpose or usage of the 204 response? I know industry-usage often diverges from specifications, but this seems... wrong.


I'm an engineer on the Edge team, and see the issue to which you are referring. For the time being, I'd encourage you to use a 200 OK response, even when you're simply sending headers (as is fairly common).

I do agree that two requests is out of the norm, and that a 204 should probably not prevent the subsequent GET request.

I have filed a bug for our team to evaluate this issue more thoroughly.

https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8499759/

0 投票
0 回答
958 浏览

angularjs - AngularJS:错误 204(无内容)

我有这个角度控制器:

这是我的数据服务文件:

此 dataService.js 调用存储库中的 GetOrganizationById 方法,如下所示:

存储库成功获取信息,发送回 dataService.js 并到达 organizationsController.js 中的这一行。我可以在 Chrome 调试器中看到:

但是在下一行,数据丢失,系统返回 204 错误代码:无数据。

知道为什么控制器不接受在变量“结果”中发送的数据吗?

我在 Visual Studio 2015 EF 和 C# 后端工作。但问题只是在前端,因为我得到了信息,而且我也看到了 Postman

0 投票
1 回答
201 浏览

.htaccess - 浏览器缓存如何处理热链接图像 + 204 响应?

我在网上看到了一些相互矛盾的答案,我试图从根本上理解这一点。假设我的网站上有一张图片热链接(是的,经许可):

  1. 假设所有相关方都启用了浏览器缓存,该图像是否会被缓存(也就是来自外部站点的图像甚至可以缓存)?
  2. 如果外部服务器决定在同一个文件位置提供不同的图像,比如 .htaccess 重写,缓存会被破坏吗?
  3. 如果外部服务器决定在 ?randomquerystring此后提供相同的图像,缓存会被破坏吗?
  4. 如果外部服务器响应 HTTP 状态代码 204 而不是实际提供图像,那么缓存会发生什么情况?

谢谢!祝大家节日快乐。

0 投票
1 回答
9976 浏览

ruby-on-rails - Rails 5找不到模板错误

运行时终端出错rails s

看来这实际上是 rails 中的一个未知格式错误,它作为 204 No Content 错误传递。我对rails真的很陌生,并且为一门课程做这件事。

我有一个只有一个def confirm动作的控制器。它在我的文件中的任何地方都没有重复。与之前的大多数帖子不同,此操​​作中没有respond_to方法。

错误实际上来自哪里?我不知道我是否应该查看配置或重新工作控制器

这是我的宝石文件:

编辑.html.erb

0 投票
1 回答
1654 浏览

ruby-on-rails-5 - Rails 5 204 无内容

找不到 ChefsController#create 的模板,渲染头:no_content 已完成 204 无内容

这是 Rails 5 中的一个问题,有助于 API

我已经看过这篇文章和其他几篇文章,但我仍然被卡住了。 https://www.rubyplus.com/articles/2771-Rails-5-Basics-View-to-Model


这是我尝试调试的过程:

鉴于我正在运行本地服务器
并且我在 localhost:3000/signup
当我输入名称、电子邮件、密码和密码确认时
然后我希望创建一个新的厨师

相反,我收到 204 No Content 错误:

鉴于我正在运行本地服务器
并且我在 localhost:3000/signup
当我输入名称时,没有电子邮件,密码和密码
确认然后我希望看到错误

相反,我收到 204 No Content 错误并且在本地视图中没有看到任何错误

当我运行测试时,我收到此错误:

当我运行 $ rails 控制台时,可以创建 Chef

啊哈,我刚刚注意到厨师的身份证都是零。为什么?哦,他们不是,:(

我删除了第一个没有密码的厨师,以防万一它引起问题,但它没有改变。


我以为我即将解决这个问题,但我没有。

我记得如果你没有正确关闭它,调试器会使你的服务器挂起。我以为这可能是我的问题,但事实并非如此。我重新启动了我的虚拟机并再次运行服务器并收到相同的错误。

我已将调试器放在 create 方法中,但我的服务器从未到达调试器。它被困在新方法上。

在我的本地视图中:local::3000/chefs/3

在此处输入图像描述

我的代码:

配置/路由.rb

应用程序/模型/chef.rb

应用程序/控制器/chefs_controller.rb

我添加了 index 和 show 方法只是为了确保有可用的模板。

app/views/chefs/new.html.erb

app/views/chefs/show.html.erb

测试/集成/chef_signup_test.rb

数据库/schema.rb