-1

I am trying to get a simple PUT and DELETE request to work via JQuery but I get 405. I am new to JQuery, rather learning it.

I am creating two HTML files and deploying it in tomcat 8.5 and running them via 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>

And another file test.html

with just simple text GEEKSFORGEEKS.

Simply following the page --> https://www.geeksforgeeks.org/how-to-send-a-put-delete-request-in-jquery/

But I get

405 - method not allowed

one the button click.

Please suggest.

sideshowbarker
  • 62,215
  • 21
  • 143
  • 153
ViS
  • 1,005
  • 1
  • 11
  • 32
  • It sounds like the requests are being made as intended, the server simply doesn't allow PUT and DELETE requests for that URL. In the tutorial their server may simply be silently accepting those requests. What are you expecting your server to do with those requests and why? – David Mar 19 '21 at 15:28

1 Answers1

-1

Well, your test is a success.

405 - means that the server knows the method but does not allow to perform it.

The response MUST contain an Allow header containing the allowed methods.

source:

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

Celeb
  • 88
  • 4