# Form submission methods in JavaScript

Forms can be submitted in two ways: with the GET method or POST method. The form submission method is controlled by the `method` attribute of a form.

For example, let's specify the GET submit method for the form:

`<form action="/handler/" method="GET"> <input name="test1"> <input name="test2"> <input type="submit"> </form>`

And now POST method:

`<form action="/handler/" method="POST"> <input name="test1"> <input name="test2"> <input type="submit"> </form>`

Let's now see what is the difference between the two submit methods. In the case of the GET method, form data will be visible in the browser in the form of so-called query string, which is pairs of the key-value form, where a key is the name of form element, and a value is the data entered into it. In this case, pairs of values will be separated by ampersands.

The data sent by the GET method will end up on our server in the `get` property of the data object:

`export default { '/handler/': function(data) { console.log(data.get); // outputs to the server console return 'form data received'; } }`

And the data sent by the POST method will end up on our server in the `post` property of the data object:

`export default { '/handler/': function(data) { console.log(data.post); // outputs to the server console return 'form data received'; } }`

For brevity, we can perform destructuring to get our data into a separate variable:

`export default { '/handler/': function({get, post}) { console.log(get); console.log(post); return 'form data received'; } }`
← →
↑
en ru