2

I saw the below code in w3school. I was wondering is this considered a POST request or a GET request. I only changed the action location to go to a java servlet rather than php.

<!DOCTYPE html>
<html>
<body>
  <form id="myForm" action="/action">
    First name: <input type="text" name="fname"><br> Last name: <input type="text" name="lname"><br><br>
    <input type="button" onclick="myFunction()" value="Submit form">
  </form>

  <script>
    function myFunction() {
      document.getElementById("myForm").submit();
    }
  </script>
</body>
</html>
Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
Qwerty Qwerts
  • 1,521
  • 2
  • 9
  • 13

1 Answers1

3

<form>'s default method is GET.

So it is considered as a GET request. You'll see all the parameters are being binded to the URL once the form is submitted.


EDIT (answering this comment):

Easiest way to change the method of the form is to mention it in method attribute in the <form> tag.

<form method='POST' id="myForm">

Or you can use javascript as below,

document.getElementById("myForm").method = "POST";
Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80