GET vs POST in Ajax

GET is designed for getting data from the server. POST (and lesser-known friends PUT and DELETE) are designed for modifying data on the server.

A GET request should never cause data to be removed from an application. If you have a link you can click on with a GET to remove data, then Google spidering your site could click on all your “Delete” links.

The canonical answer can be found here, which quotes the HTML 2.0 spec:

If the processing of a form is idempotent (i.e. it has no lasting
observable effect on the state of the
world), then the form method should be
GET. Many database searches have no
visible side-effects and make ideal
applications of query forms.

If the service associated with the processing of a form has side effects
(for example, modification of a
database or subscription to a
service), the method should be POST.

In your AJAX call, you need to use whatever method your server supports. You should always design your server so that operations that modify data are called by POST/PUT/DELETE. Other comments have links to REST, which generally maps C/R/U/D to “POST or PUT”(Create)/GET(Read)/PUT(Update)/DELETE(Delete).

Leave a Comment