I am facing problem to call user defined web api function in MVC4 Please suggest how can i do this. i am first time using web api.
My API Function :
public List<Voice> GetVoicesByStatus(string Status)
{
List<Voice> Voc = db.Voices.Where(x => x.Status == Status).ToList();
if (Status == null)
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
return Voc;
}
Ajax Method :
function GetVoicesByStatus(status) {
$.ajax({
type: 'GET',
url: 'http://xx.xx.xx.xx.xx:xx/api/Applications/VoicesByStatus/' + status,
data: JSON.stringify({}),
contentType: 'application/json',
dataType: 'json',
headers: { 'AuthToken': '2FEA7374-EBA2-4367-9492-6DB3334AD2AF' },
success: function (data) {
for (var i = 0; i < data.length; i++) {
var str = "<tr><td>" + data[i].ID + "</td><td>" + data[i].APIKey + "</td><td>" + data[i].CreatedBy + "</td><td><a href='#' onclick='fnDelete('" + data[i].ID + "')'>Delete</a></td></tr>";
$("#app").append(str);
}
}
});
}
Error :
