I have such a form.
<form id="hiddenForm" method="post" action="/my-controller/my-action/" enctype="multipart/form-data">
<input type="hidden" id="HiddenFormInput" name="HiddenFormInput">
</form>
which is created by a web page accessible through https://[my-server]/my-controller/my-action/
, which is also the action that the form points to.
On the server side, I distinguish between requests GET
and POST
. Either the page is displayed explicitly ( GET
), or some results are displayed depending on the values ββof the form ( POST
).
When I use jQuery to submit the form (I DO NOT use AJAX here, just submitting the form), as in this snippet,
$("#hiddenForm").submit();
then jQuery seems to submit this form using GET
, although it is explicitly marked for submit using POST
. Even alert($("#hiddenForm").attr("method"));
always gives "post"
. However, this unwanted behavior only occurs if the page has been loaded with GET
. If the page is specified with POST
, i.e. The form has already been submitted at least once, everything works as expected.
Update
The problem was plain old preventDefault()
. The button that initiated the sending had its own functionality. It was a hyperlink. Therefore, I had this chain of actions.
- Hyperlink to
https://[my-server]/my-controller/my-action/#
- Submit a form with an action
https://[my-server]/my-controller/my-action/
.
, GET
. https://[my-server]/my-controller/my-action/#
, . , .
https://[my-server]/my-controller/my-action/#
( , )https://[my-server]/my-controller/my-action/
.
, .