How to pass form data using POST method and JS submit() ?
I would like not to use AJAX.
I can achieve that by using JS and GET method, but my goal now is to use JS (probably with submit() ) and POST method.
Please give a simple working example.
Thank you!
Edited: Sorry, I will be more specific.
Here is a simple code I have:
<form name=\"myform\" action=\"\">
Search: <input type='text' name='query' />
<a href=\"javascript: submitform()\">Search</a>
</form>
<script type=\"text/javascript\">
function submitform() { document.myform.submit(); }
</script>
When I insert “word” into the input field and press Search, the URL becomes “../index.php?query=word” and that means that form data is passed like GET method.
And my goal is to remove any form data from URL and pass it like with POST method.
Edited: ohh.. I just added method=post and no form data in the URL anymore 🙂
Just have a form and submit it.
EDIT: OP has clarified question
Specify a
methodattribute on your form.It will cause the form to be submitted as a POST.