POST 表单并阻止响应 [英] POST form and prevent response

查看:30
本文介绍了POST 表单并阻止响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下表格:

<form method="post" action="http://domain.com/api.json?param=value"></form>

提交此表单后,这会将我的文档替换为来自 http://domain.com/api.json 的回复.

On submission of this form, this will replace my document with a response from http://domain.com/api.json.

是否可以发布此表单,但阻止接收响应,并使用 form 保留现有的 HTML?

Is it possible to POST this form, but prevent receiving a response, and keep the existing HTML with the form?

推荐答案

Send an HTTP 204 No Content 响应 而不是通常的 200 OK 响应.

Send an HTTP 204 No Content response instead of the usual 200 OK response.

10.2.5 204 无内容

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.

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

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

这篇关于POST 表单并阻止响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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