Is it possible to trigger an HTTP DELETE request from an HTML form?

后端 未结 2 1381
被撕碎了的回忆
被撕碎了的回忆 2021-01-07 23:23

I have an ASP.NET MVC project and I have a single action that accepts GET, POST, and DELETE requests. Each type of request is filtered via attributes on my controllers

相关标签:
2条回答
  • 2021-01-07 23:39

    Using XMLHttpRequest, it's not only the "best practice", it's really the only way.

    0 讨论(0)
  • 2021-01-07 23:40

    i don't believe this is possible. the method attribute of form elements in HTML4 & XHTML 1.0 will only accept GET or POST. in addition, standard configs of most webservers will deny DELETE and PUT requests. assuming you have configured your webserver to allow methods like PUT / DELETE (such as WebDav does), you could then create your own HTTP request:

    DELETE /resource.html HTTP/1.1
    Host: domain.com
    

    and handle it appropriately. however, there's no way to do this via a current HTML form. for interest's sake, there is some discussion for DELETE support in HTML5.

    0 讨论(0)
提交回复
热议问题