Reputation: 113
I am trying to call an API written by me. However when I am trying to call a POST method via $.ajax
it returns an error:
The requested resource does not support http method 'GET"
When I try to call via Postman, I get the desired results. On top of this, the $.ajax
for the same method works for all calls. Here is my API method
[HttpPost]
[Route("api/Ticket/GetTicketsAssignedToTechnician/")]
public List<Ticket> GetTicketsAssignedToTechnician([FromBody]string technicianEmail)
{
return dbManager.GetTicketsByAssignedTechnician(technicianEmail);
}
postData: function (serviceURL, parameterValue, success, failure, error) {
$.ajax({
url: serviceURL,
method: "POST",
data: JSON.stringify(parameterValue),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: success,
failure: failure,
error: error
});
}
Here is call to $.ajax
:
Utility.postData(Dashboard.hostURL + "Ticket/GetTicketsAssignedToTechnician/", email, function(data) {
console.log(data);
}, function(data) {
console.log("failure." + data.responseText);
}, function(data) {
console.log("Error." + data.responseText);
});
Upvotes: 1
Views: 1335
Reputation: 337701
The issue is because you're using the wrong property name in the $.ajax
options. it's type
, not method
. Therefore jQuery uses the default, which is GET
.
$.ajax({
url: serviceURL,
type: "POST", // < change here
data: parameterValue, // no need to JSON.stringify here, jQuery will do it for you
// other options...
});
Upvotes: 2
Reputation: 3856
try to do as below
$http({
method: "POST",
url: serviceURL,
contentType: "application/json; charset=utf-8",
data: JSON.stringify(parameterValue),
dataType: 'JSON'
})
Upvotes: 0