Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify DELETE method in a link or form?

Rfc2616 lists many methods besides GET and POST, like, say, DELETE, PUT etc. Method field in html forms, though, seems to be allowed to specify only GET or POST.

Is it possible to create a link or form in a html page that uses a request method that is not GET or POST?

like image 387
Maurício C Antunes Avatar asked Aug 03 '11 12:08

Maurício C Antunes


People also ask

Can I use Delete method in form?

Browsers do support PUT and DELETE but it only by using request via AJAX, but not via 'HTML form' submission. In both HTML4 and HTML5 spec, it says that the only HTTP methods that HTML form element should allow are "GET" and "POST". There is no clear reason why PUT and DELETE are not supported by 'HTML form'.

What is http DELETE method?

The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY be overridden by human intervention (or other means) on the origin server.

Which method performs an http DELETE* syntax?

The HTTP DELETE method is used to delete a resource from the server. Unlike GET and HEAD requests, the DELETE requests may change the server state. Sending a message body on a DELETE request might cause some servers to reject the request. But you still can send data to the server using URL parameters.


1 Answers

Was trying to figure this out for a rails app that was using Angular on the front end; these seems to work for that environment:

<a data-confirm="Are you sure?" data-method="delete" href="/link-to-resource" rel="nofollow">Delete</a> 

Edit: Just to give everyone a heads up, I think you still need to have jQuery for this to work. I removed jQuery and it stopped working; I put it back and it started working.

like image 63
AlmightyWhy Avatar answered Sep 27 '22 19:09

AlmightyWhy