2016-05-30 57 views
0

我想使用web服务删除Angular JS中的一行但无法执行。这里是我的代码:的script.js无法删除Angular 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> 

我得到员工ID中的script.js如EID但F12调试后,这个错误就要 http://localhost:55735/EmpWebService.asmx/DeleteEmployee 500(内部服务器错误)

+0

你能发布有关错误的更多细节吗?像堆栈跟踪 –

+0

我认为你的问题与AngularJS无关,而是与你的服务器实现有关。请检查您发送到您的服务器(仍F12),服务器响应主体(如果有)的参数类型。 – Neozaru

回答

1

框架您的要求是这样的:

$http({ 
    method: "POST", 
    url: 'EmpWebService.asmx/DeleteEmployee', 
    data: {Id: EID}, 
    headers: {'Content-Type': 'application/json; charset=utf-8'} 
}) 
.then(function(reponse){...}); 

请注意:Id应该是预期的路线中的参数的名称,如果它不是,那么请改变代码相应

+0

非常感谢你,最后你的代码工作 –

0

看来你有一个错字,你应该叫宁与$http.postdata

代替:

​​
+0

我已经使用数据而不是EID。但数据有空白值,所以我通过了EID。 –

+0

我想你应该通过数据构建这样的数据:var data = $ .param({“EID”:EID});'。我想服务器端期待''EID“'作为参数名称。 –

+0

当通过F12进行调试时,我发现控制器终止于$ http.post行(“EmpWebService.asmx/DeleteEmployee”,data,config) –