0

I am always confused whether to have GET or POST method in my jQuery and Controller, can someone explain the basic difference between them, I do know that we can have both GET and POST method for single request mapping.. but am not sure about the exact difference between them

Thanks in advance

Manu
  • 57
  • 1
  • 10
  • 2
    Possible duplicate of [When should I use GET or POST method? What's the difference between them?](http://stackoverflow.com/questions/504947/when-should-i-use-get-or-post-method-whats-the-difference-between-them) – fvu Nov 24 '15 at 17:40

5 Answers5

0

The difference are similar than in SQL. GET returns an object selected with some parameters (similar as select in SQL) and POST creates an object.

Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
0

Here is a simple comparison between GET and POST, by the W3C: HTTP Methods: GET vs. POST.

Take a look at the RFC for more details.

Community
  • 1
  • 1
izilotti
  • 4,757
  • 1
  • 48
  • 55
0

GET method/request means sending the request either by clicking Hyperlink or by manually entering the URL.In the GET request only request header will be there.But when it comes to POST method/request it will have the Request header and Request Body.As part of the Request Body u can send data/payload to process.

In spring MVC, SimpleFormController u can map both the GET and POST methods with same request mapping. SimpleFormController will automatically differentiates the request by seeing the Data/Payload as part of the request.

tech.yenduri
  • 586
  • 5
  • 7
  • hey... yeah I understand these differences, but the problem comes when, for instance I have a ajax call which is sending some data to controller either as path variable or as parameter... and controller will not have any return value... in this case which one to use ?? – Manu Nov 25 '15 at 03:58
  • Yeh... If the data you are sending/passing is to be processed and persisted you can go with POST. If the data you are sending is just for request something you can go with GET... If this doesn't clarifies..Can you be more precise about the data you are sending..like header information or some other payload kind of thing.. – tech.yenduri Nov 25 '15 at 05:46
  • actually am sending a string from ajax call to controller the value will be stored to DB, controller will not return anything.... – Manu Nov 25 '15 at 05:55
0

GET method is used purely when you need to retrieve data from the controller/application. As a best practice, it is assumed that there is no change in the state of data/application. You are just retrieving data that you need.

POST is something where you need to pass on some data to the application where you are expecting some data processing on it. So if your intention is to change some of your data/state of your application, use POST.

asg
  • 2,248
  • 3
  • 18
  • 26
  • ok.. for example I have an ajax call where I will send one string and a controller which receives that string and store it in database and there is nothing that the controller returns... which one to use GET or POST – Manu Nov 25 '15 at 04:38
  • It is a POST method call as you are updating some data in your database. – asg Nov 25 '15 at 05:00
  • You can also take a look at PUT option. Here is the link - http://stackoverflow.com/questions/630453/put-vs-post-in-rest – asg Nov 25 '15 at 05:03
0

Basic difference between GET and POST-

GET request - GET is usually used when you want to request some data from the server. It has request header which contains URL of the requested resource and the request body is empty. You can pass some parameters as query string in the GET request, but they appear in the URL.

Check below example:

...form?name="Name"&address="Address" which means there exists a resource named form on the server and you are passing parameters name and address with values Name and Address.

POST request- POST is used when you want to make some changes to the data on the server like posting new data, updating data, uploading files etc. It has request header but unlike GET here the data is passed in the request body hence the data is hidden from the user.

Use POST over GET in below cases:

  1. Passing large amount of data to server : You might not want to pass large amount of data in the URL e.g. uploading files, URL would be very large hence use POST in such cases.
  2. Hide data from user : Since data is passed in request body, it will be hidden from the user. Even if the user bookmarks the URL it will not be visible to the user.
Hetal Rachh
  • 1,393
  • 1
  • 17
  • 23