簡體   English   中英

AngularJS通過$ http.post將更新的數據發送到php頁面

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

我剛剛在angularJS應用程序中添加了編輯表格單元格的功能。 我現在要做的是通過將更新的數據發送到我的PHP腳本來反映數據庫中的更改,我對如何實際重新發送更新的表格感到困惑。

我的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>

控制器歸功於編輯部分的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();
}]);

看起來您正嘗試使用單個“ Update按鈕單擊更新整個表。 您當前的代碼試圖訪問ctr元素,這使得c超出范圍的button

嘗試將data變量傳遞給update函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM