GET vs POST in Ajax

Well, as for GET, you still have the url length limitation. Other than that, it is quite conceivable that the server treats POST and GET requests differently; thus the need to be able to specify what request you're doing.


You should use the proper HTTP verb according to what you require from your web service.


When dealing with a Collection URI like: http://example.com/resources/

GET: List the members of the collection, complete with their member URIs for further navigation. For example, list all the cars for sale.

PUT: Meaning defined as "replace the entire collection with another collection".

POST: Create a new entry in the collection where the ID is assigned automatically by the collection. The ID created is usually included as part of the data returned by this operation.

DELETE: Meaning defined as "delete the entire collection".


When dealing with a Member URI like: http://example.com/resources/7HOU57Y

GET: Retrieve a representation of the addressed member of the collection expressed in an appropriate MIME type.

PUT: Update the addressed member of the collection or create it with the specified ID.

POST: Treats the addressed member as a collection in its own right and creates a new subordinate of it.

DELETE: Delete the addressed member of the collection.


Source: Wikipedia


Two primary reasons for having them:

  1. GET requests have some pretty restrictive limitations on size; POST are typically capable of containing much more information.

  2. The backend may be expecting GET or POST, depending on how it's designed. We need the flexibility of doing a GET if the backend expects one, or a POST if that's what it's expecting.


Another difference between GET and POST is the way caching is handled in browsers. POST response is never cached. GET may or may not be cached based on the caching rules specified in your response headers.