【问题标题】:Simple JQuery failing with 405 method not allowed不允许使用 405 方法的简单 JQuery 失败
【发布时间】: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


【解决方案1】:

嗯,你的测试成功了。

405 - 表示服务器知道方法但不允许执行。

响应必须包含一个 Allow 标头,其中包含允许的方法。

来源:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405

【讨论】:

  • 当然,让我用一个实际的服务器请求来尝试它,它会发回响应。
猜你喜欢
  • 1970-01-01
  • 2016-01-23
  • 1970-01-01
  • 1970-01-01
  • 2012-10-26
  • 1970-01-01
  • 1970-01-01
  • 2012-04-30
  • 2011-09-01
相关资源
最近更新 更多