在 Angular JS 中通过 WEB API 将数据插入数据库

问题描述 投票:0回答:1

我是 Angular JS 和 Web API 世界的新手。最近在通过 Web API 和 Angular 将数据发送到数据库时遇到困难。我能够从 webapi 加载 JSON 数据。任何帮助将不胜感激。 我的html:

<div class="container-fluid" ng-controller="SubmitDataCtrl">
     <div class="container text-center" style="margin-bottom:5px">
         <div id="divTables">
             <table id="tbl_SMDetails" class="display responsive nowrap aleft" cellspacing="0" width="100%">
                 <thead>
                     <tr>
                         <th class="all">Name</th>
                         <th class="all">CTSID</th>
                         <th class="all">FDID</th>
                         <th class="all">Name of the Project</th>
                         <th class="all">Effort Hour</th>
                         <th class="all">Month</th>

                     </tr>
                 </thead>

                 <tbody>
                     <tr ng-repeat="showData in loadData">
                         <td>{{showData.EmpName}}</td>
                         <td>{{showData.EmpCognizantID}}</td>
                         <td>{{showData.FDID}}</td>
                         <td><input id="Text1" type="text" />{{showData.projectName}}</td>
                         <td><input id="Text1" type="text" />{{showData.effortHour}}</td>
                         <!--<td>{{date | date:'MM-dd-yyyy}}</td>-->
                         <td>{{showData.date}}</td>
                     </tr>
                 </tbody>
             </table>
         </div>

     </div>
   <div>
       <a ng-href='#SubmitData' class="btn  btn-default" ng-click='go()'>Submit</a><span></span>
       <a ng-href='#SubmitData' class="btn  btn-default" ng-click=''>Reset</a>
       
   </div> 
     </div>

我的服务页面如下所示:

var request = $http({
                        method: method_args,
                        url: myConfig.ServiceURL + url,
                        data: JSON.stringify(input_data),
                        Accept: 'application/json',
                        headers: {'Content-Type':'application/json'},
                        xhrFields: {
                            withCredentials: true
                        }
                    });
                }

我的控制器是

App.controller("SubmitDataCtrl", function($scope, ajaxService) {
//login user    
ajaxService.MakeServiceCall("employee/GetTeamMember?         superVisiorCogniID=256826", "GET", "")
.then(function effortData(data)
{
  // alert(data);
  $scope.date = new Date();
  $scope.loadData = data;
  showData = $scope.loadData;
  for (var i = 0; i < showData.length; i++)
  {
      //alert(showData[i].EmpName + showData[i].EmpCognizantID + showData[i].FDID);
  }});
 
$scope.go = function()
{

   //alert('clicked');
   ajaxService.MakeServiceCall("effort/SaveTeamEfforts?hourLoadDate=08/20/2015&hourLoadByCogniID=256826&forMonth=July", "POST", Employee).then(function save() {
        var Employee =
            {
                "EmpCogniID": showData[i].EmpCognizantID,
                "FDTimeCardHour": showData[i].effortHour,
                "HourLoadDate": 08/11/2015,
                "HourLoad`enter code here`By": "256826",`enter code here`
                "ForMonth": "july"
            }
   }).success(function (Employee)
   {
       $scope.showData[i] = Employee;
   });
   alert(Employee);    }});
javascript json angularjs post webapi
1个回答
0
投票

如果不知道 API POST 调用应该做什么,就很难回答。

您能否通过在浏览器中使用 REST 测试器来执行您对effort/saveTeamEfforts 所做的 POST 是否有效?

如果这有效,您应该在 API 调用中添加一个 .error 函数,并查看返回的错误,如上面 dan 所建议的那样

L

© www.soinside.com 2019 - 2024. All rights reserved.