0

On my edit page, I am using an api controller.

Here is my $.ajax:

var settings = {};
settings.baseUri = '@Request.ApplicationPath';
var infoGetUrl = "";
if (settings.baseUri === "/ServerProjectName") {
    infoGetUrl = settings.baseUri + "/api/controllerName/";
} else {
    infoGetUrl = settings.baseUri + "api/controllerName/";
}

$("#Edit-Btn").on("click",
    function(e) {
        $("form").validate({
            submitHandler: function() {
                e.preventDefault();

                $.ajax({
                    method: "PUT",
                    url: infoGetUrl,
                    data: $("form").serialize(),
                    success: function(data) {
                        toastr.options = {
                            onHidden: function() {
                                window.location.href = newUrl;
                            },
                            timeOut: 3000
                        }
                        toastr.success("Successfully edited.");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        var status = capitalizeFirstLetter(textStatus);

                        toastr.error(status + " - " + jqXHR.responseText);
                    }
                });
            }
        });
    });

Below this method is another ajax function for 'DELETE' and that works perfectly. Only PUT methods are giving me this error.

When I submit, I receive an error saying:

The requested resource does not support http method 'PUT'

I have looked at this but not quite understanding. I am using IE 11, so I think it should be supported.

Any ideas or help is greatly appreciated.

enter image description here

Community
  • 1
  • 1
Grizzly
  • 5,873
  • 8
  • 56
  • 109

1 Answers1

1

The reason you're getting this message is that the API that you're trying to use doesn't support the HTTP PUT method.

Typically, if you were using web api 2.0 you'd have an attribute on the web method that has [HttpPut] if it supported PUT. There are other ways to flag an API to support Put as well but not typically used.

The easiest way to confirm that your API is the issue is to use Postman to try to use the API and that eliminates any issues you may have with your javascript.

Avitus
  • 15,640
  • 6
  • 43
  • 53
  • I am testing in Postman right now, and it is working. I am editing a property via Postman, then refreshing my page and the property is the value I edited it to – Grizzly May 09 '17 at 13:29
  • Are you sure that you're choosing put in postman? Can you update the question with the screenshot from postman? – Avitus May 09 '17 at 13:35
  • It's because your javascript doesn't append the 6 that you're using in postman – Avitus May 09 '17 at 13:40