开发者

Is there a way to ignore form response?

开发者 https://www.devze.com 2023-01-08 10:56 出处:网络
Is there a way to specify a form either through type or action url to not open the response? In other w开发者_开发技巧ords I would like to send the info to the server, but not do anything on the clien

Is there a way to specify a form either through type or action url to not open the response? In other w开发者_开发技巧ords 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.


try this:

<iframe id="invisible" ...

<form target="invisible" ...


I found that name attribute should be specified as well (I tested in IE11). E.g:

<iframe id="invisible" name="invisible" style="display:none;"></iframe>
<form method="post" target="invisible" action="url.com/whatever?x=y" id="fileForm" enctype="multipart/form-data">


With ASP.NET you could have a page that processes the form post and simply end the response right away, this will leave the user at the same page.

However, no response to the user at all is not the best user experience.....

0

精彩评论

暂无评论...
验证码 换一张
取 消