我无法使用php和angularjs将使用更新功能的记录更新到数据库中


i am not able to update the record using update function into the database using php and angularjs

这是我的表代码:

<tbody>
      <tr ng-repeat="tabdata in tabledata">
                <td>
                    <div ng-hide="editdata[tabdata.id]">{{tabdata.name}}</div>
                    <div ng-show="editdata[tabdata.id]"><input type="text" ng-model="tabdata.name"></div>
                </td>
                <td>
                    <div ng-hide="editdata[tabdata.id]">{{tabdata.city}}</div>
                    <div ng-show="editdata[tabdata.id]"><input type="text" ng-model="tabdata.city"></div>
                </td>
                <td>
                    <button ng-hide="editdata[tabdata.id]" ng-click="edit(tabdata)">EDIT</button>
                    <button ng-show="editdata[tabdata.id]" ng-click="update(tabdata)">UPDATE</button>
                </td>
            </tr>
            </tbody>

这是我的代码:

var app=angular.module('myApp',[]);
app.controller('myCtrl',['$scope','$http',function($scope,$http){

在这里,我从数据库表中获得数据:

    $http.get('fetch.php').success(function(data) {
        $scope.tabledata = data;
    });

    $scope.editdata={};

此功能用于编辑按钮:

    $scope.edit=function(tabdata){
        $scope.editdata[tabdata.id]=true;
    };

这是用于更新按钮:

    $scope.update=function(tabdata) {
        $scope.editdata[tabdata.id] = false;

在这里,我必须调用ajax方法来更新数据库中的值。或者我们也可以使用服务功能?

我在fetch.php文件中使用$input使用orm文件连接数据库。。

        $http({
            method:"post",
            url:'fatch.php',
            data:{
            }
        })
    };
}]);

问题是,当我点击编辑按钮时,它会被修改,但在那之后,当我编辑一些行数据时,它只更新静态页面中的数据。我还必须更新我的数据库表。那么该怎么做呢?

我必须使用SERVICE函数和AJAX调用方法更新我的数据库表。知道怎么做吗?

以下是您的案例的解决方案:

$scope.update=function(tabdata) {
    $scope.editdata[tabdata.id] = false;
    $http({
        method:"post",
        url:'fetch.php',
        data:{
               // your data to send
        }
    }).then(function(success){
        // refresh live your tabledata angularjs will do the job for you
        $http.get('fetch.php').success(function(data) {
            $scope.tabledata = data;
        });
    })
}

您不需要Ajax调用。