有没有办法忽略表单回复? [英] Is there a way to ignore form response?

查看:158
本文介绍了有没有办法忽略表单回复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过类型或动作url来指定表单来不打开响应?换句话说,我想将信息发送到服务器,但不在客户端上做任何事情。我知道我可以使用ajax并忽略响应,但我希望避免将所有js添加到我的代码中。如果可能的话。



编辑:我不是故意要限制自己到HTML表单。在我的情况下,服务器端解决方案也是可以接受的。在服务器端提交表单提交后,服务器返回HTTP 204(无内容)。根据 HTTP 1.1规范


10.2.5 204无内容



服务器已完成请求
,但不需要返回一个
实体主体,并且可能想要返回
更新的元信息。响应
可以包含新的或更新的
元信息,形式为
实体标题,如果存在的话
应该与
请求的变体相关联。



如果客户端是用户代理,则
不应将其文档视图
从导致请求发送到
的文档视图中更改。此回应主要是
,旨在允许输入
的动作,而不会导致
更改为用户代理的活动文档视图
,尽管任何新的或更新的
元信息应该应用于
当前在用户
代理的活动视图中的文档。



204响应不能包含
消息因此总是
被头字段后的第一个空行
终止。


听起来就像你想要的。


Is there a way to specify a form either through type or action url to not open the response? In other words I would like to send the info to the server, but not do anything on the client. I know I can use ajax and ignore the response, but I would like to avoid adding all the js to my code if possible.

Edit: I didn't mean to limit myself to the html form. In my case server side solutions were also acceptable.

解决方案

Have the server return HTTP 204 (No Content) after the form submission. According to the HTTP 1.1 spec:

10.2.5 204 No Content

The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.

If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

This sounds like exactly what you want.

这篇关于有没有办法忽略表单回复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆