REST架构下,浏览器怎么发送put与delete请求?
來源:http://www.myexception.cn/j2ee/318527.html
例如后臺已經搞定,REST服務已經建好了,那么前臺瀏覽器怎么使用呢?
------解決方案--------------------------------------------------------
前端比較麻煩,因為:
The other HTTP methods (i.e. other than GET and POST) are not available in HTML 4.1 or XHTML 1.0.
也就是說實際上HTML5以前,FORM都僅支持GET和POST。
即便你嘗試自己用Ajax來做,都未必能成功。
在jQuery的文檔中說:
The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.(最后一句話:不是所有瀏覽器支持其它方式)?
------解決方案--------------------------------------------------------
可以用POST來代替PUT和DELETE, 比如你可以埋一個hidden field叫 _method, <input type= "hidden " name= "_method " value= "PUT "> . 這樣,你在后臺可以根據這個字段來識別.
總結
以上是生活随笔為你收集整理的REST架构下,浏览器怎么发送put与delete请求?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华为与 Hansol PNS 达成合作,
- 下一篇: html里面超链接alt_前端html-