$http.delete('/departments', { Id: d.DepartmentId }).success(function (responseData) { alert('ok'); });
But the record is not deleted.
I assumed the second parameter is a data parameter, I should thought early that second parameter has many options. Another lesson learned, aside from not reading the AngularJS doc, handling errors should be our second nature, the errors provided by ServiceStack helps a lot for debugging why the particular method for RESTful deletion is not routed to its proper service method.
Upon adding .error callback, lot of guessworks were avoided on why there's a 405 error, which naturally led me to read AngularJS doc. $http delete has a config parameter, the second parameter is not directly a data paramater
To correctly pass the data parameter with AngularJS:
$http.delete('/departments', { params : { Id: d.DepartmentId } }).success(function (responseData) { alert('ok'); }).error(function(data, status, headers, config) { console.log(data); alert(data.ResponseStatus.Message); alert(status); });
Obligatory xkcd reference: http://xkcd.com/293/
No comments:
Post a Comment