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.
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.