Reputation: 171
I am trying to delete a row in Angular JS using web service but unable to do it. Here is my code:script.js
$scope.DeleteEmployee = function (EID) {
var data = $.param({
EID: $scope.EmpId
});
var config = {
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}
$http.post("EmpWebService.asmx/DeleteEmployee", EID, config)
.then(function (response) {
alert("Deleted successfully.");
$scope.getEmployee();
});
}
employee.aspx
<td>
<a href="#" ng-click="DeleteEmployee(employee.EmpId)">Delete</a>
</td>
I am getting employee id in script.js as EID but after debugging by F12 this error is coming http://localhost:55735/EmpWebService.asmx/DeleteEmployee 500 (Internal Server Error)
Upvotes: 0
Views: 76
Reputation: 792
Frame your request like this:
$http({
method: "POST",
url: 'EmpWebService.asmx/DeleteEmployee',
data: {Id: EID},
headers: {'Content-Type': 'application/json; charset=utf-8'}
})
.then(function(reponse){...});
Please note that Id
should be the name of the parameter expected in your route if it is not then please change the code accordingly
Upvotes: 1
Reputation: 1103
It seems you have a typo, you should rather call $http.post
with data
:
$http.post("EmpWebService.asmx/DeleteEmployee", data, config)
instead of :
$http.post("EmpWebService.asmx/DeleteEmployee", EID, config)
Upvotes: 0