I have a problem with PUT in Ajax.
If I use fiddler and execute a PUT to the URL: http://domain.com:58226/api/Person/1 , with Request body: {“firstName”:”Stan”,”lastName”:”Dard”}, it works.
But when I use ajax to do the same, it doesn’t work:
$.ajax({
data: '{"firstName":"Stan","lastName":"Dard"}', //{action:'x',params: ['a','b','c']}
url: 'http://domain.com:58226/api/Person/'+id,
type: 'PUT',
success: function(result) {
alert("Uppdaterad!");
}
});
I think the data needs to be a String. Objects are converted to querystrings which is what you are seeing here.
You can use the
JSON.stringify(obj)method to convert your Object to a String.