我正在使用下面的代码,它在我的机器上运行良好。我认为您需要在url中添加方法名delete,它应该是“
http://localhost:3413/api/person/Delete?ID=100
“
<script type="text/javascript">
function delTest() {
$.ajax({
url: 'http://localhost:3413/person/Delete?ID=100',
type: 'DELETE',
dataType: 'json',
data: { name: "Sourav Kayal" },
success: function (data, textStatus, xhr) {
console.log(data);
},
error: function (xhr, textStatus, errorThrown) {
console.log('Error in Operation');
}
});
}
</script>
<input type="button" name="delete" onclick="delTest()" value="makeCall"/>
以及API代码:
[System.Web.Http.HttpDelete]
public string Delete([FromUri] int ID, [FromBody] String name)
{
return "Delete Operation" + "ID:- " + ID + "Name:- " + name;
}