tags:

views:

30

answers:

4

I would like to know why a developer would make a POST request without using a form.

Thanks!

+2  A: 

To test the form for one. Then ajax requests can use post data. Also in php at leats you have curl wich I am pretty sure can make use of the post structure to communicate other distant pages.

Iznogood
+1  A: 

Maybe to call a REST API, or other web services that require POST, or to upload a file to a server. You could use AJAX/JavaScript on client side, and just about any server side technology to mimic POST without a form.

Traveling Tech Guy
+1  A: 

POST is an HTTP verb. Browsers use HTTP as its data protocol for fetching HTML data and POST for sending the user submitted data. Basically, any data transfer over http could use POST.

Some of the examples are :

LightX
+1  A: 

Because GET and POST do not have the same semantic value. GET requests should be generally safe to perform at any time without compromising the system, while POST requests should be used when doing something important (like accepting a monetary transaction, or, in a less dramatic way, post a comment or something like that).

So it might make sense to make a POST request through AJAX if its result will affect a system.

Source: W3C HTTP/1.1 Method Definitions, read 9.1.1 Safe Methods, 9.3 GET and 9.5 POST. Don't be afraid, it's short and to the point.

zneak
Haha I'm not afraid of reading. Thanks!
letseatfood