简体   繁体   English

AngularJS通过$ http.post将更新的数据发送到php页面

[英]AngularJS send updated data to php page via $http.post

I have just added the functionality to edit a table cell in my angularJS app. 我刚刚在angularJS应用程序中添加了编辑表格单元格的功能。 What I would like to do now is have the changes reflected in the database by sending the updated data to my PHP script, I'm a little stuck on how to actually resend the updated table. 我现在要做的是通过将更新的数据发送到我的PHP脚本来反映数据库中的更改,我对如何实际重新发送更新的表格感到困惑。

My Angular Table in question: 我的Angular Table有问题:

<tr ng-repeat="c in resultValue=(data | filter:{'type':typeFilter} | filter:dateFilter | filter:proFilter | filter:cusFilter | filter:taskFilter | filter:nameFilter)">

    <td class="jid" ng-hide="viewField">{{c.journal_id}}</td>
    <td ng-show="modifyField"><input type="text" class="in1" ng-model="c.journal_id" /></td>

    <td class="wda" ng-hide="viewField">{{c.work_date}}</td>
    <td ng-show="modifyField"><input type="text" class="in1" ng-model="c.work_date" /></td> 

</tr>
     <button ng-hide="viewField" ng-click="modify(c)">Modify</button>
     <button ng-show="modifyField" ng-click="update(c)">Update</button>

The controller thanks to a SO answer for the edit part: 控制器归功于编辑部分的SO答案:

    journal.controller('dbCtrl', ['$scope', '$http', function ($scope, $http) {

          $scope.loadData = function () {
        $http.get("http://localhost/slick/journalFetch.php").success(function(data){
                $scope.data = data;
            }).error(function() {
                $scope.data = "error in fetching data";
            });
}

  $scope.modify = function(c){

            $scope.modifyField = true;
            $scope.viewField = true;
        };


  $scope.update = function(c){
            $scope.modifyField = false;
            $scope.viewField = false;

          //AM I ABLE TO RESEND THE UPDATED (c) DATA HERE TO THE DATABASE ?

             $http({
                method: "post",
                url: "update.php",
                data: {
                    //if so how to retrieve updated c data here?
                }
             }); 
            };
  $scope.loadData();
}]);

Looks like you are trying to update the entire table with a single Update button click. 看起来您正尝试使用单个“ Update按钮单击更新整个表。 Your current code is trying to access c outside the tr element which makes c out of scope for the button . 您当前的代码试图访问ctr元素,这使得c超出范围的button

Try passing data variable to the update function. 尝试将data变量传递给update函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM