【发布时间】:2021-06-17 00:41:27
【问题描述】:
我正在尝试通过 JQuery 获得一个简单的 PUT 和 DELETE 请求,但我得到 405。 我是 JQuery 的新手,而是学习它。
我正在创建两个 HTML 文件并将其部署在 tomcat 8.5 中并通过 localhost 运行它们。
index.html
<html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> <!-- Importing the jQuery --> <script src= "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> </head> <script> function makePUTrequest() { $.ajax({ url: 'test.html', type: 'PUT', success: function (result) { // Do something with the result } }); } function makeDELETErequest() { $.ajax({ url: 'test.html', type: 'DELETE', success: function (result) { // Do something with the result } }); } </script> <body> <button onclick="makePUTrequest()"> Click for PUT request </button> <button onclick="makeDELETErequest()"> Click for DELETE request </button> </body> </html>
还有另一个文件 test.html
只需简单的文字 GEEKSFORGEEKS。
只需关注页面 --> https://www.geeksforgeeks.org/how-to-send-a-put-delete-request-in-jquery/
但我明白了
405 - 不允许的方法
单击按钮。
请提出建议。
【问题讨论】:
-
听起来请求是按预期发出的,服务器根本不允许对该 URL 的 PUT 和 DELETE 请求。在本教程中,他们的服务器可能只是默默地接受这些请求。您希望您的服务器对这些请求做什么?为什么?
标签: jquery http-status-code-405