1

HI am trying to make an HTTP PUT request to my API. I am getting back the error 405 and 415 depending on how I change the URL.

The ID I am trying to change is 26 and I want to change the testDesc to test5.

Any ideas? Thank you for your time.

function httpPut() {
  $.ajax({
    url: "https://someurl/Test/26",
    type: "PUT",
    'data': {
      testDesc: "test5",
    },
  }).done(function(data) {
    document.getElementById("testingBox7").innerHTML = JSON.stringify(data);
  });
};
2
  • 4
    405 and 415 errors imply that your server side code is not configured to receive PUT requests to the endpoint you're using. Note that you can't just change the HTTP verb - your server side code needs to have its routing configured to receive it. As such your problem is on the server side, not the client side JS. Commented Jul 12, 2022 at 7:39
  • Show your server code also. Commented Jul 12, 2022 at 9:07

1 Answer 1

2

I found a solution:

function httpPut(newName) {
  var myString = "https://https://someurl/Test/";
  $.ajax({
    url: myString + newName,
    type: "PUT",
    processData: false,
    contentType: "application/json; charset=UTF-8",
    data: JSON.stringify(data)
  }).done(function(data) {
    document.getElementById("testingBox7").innerHTML = JSON.stringify(data);
  });
};
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved by adding more information on what the code does and how it helps the OP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.