我无法使用php和angularjs使用update函数将记录更新到数据库中
这是我的表格代码:我无法使用php和angularjs使用update函数将记录更新到数据库中,php,angularjs,Php,Angularjs,这是我的表格代码: <tbody> <tr ng-repeat="tabdata in tabledata"> <td> <div ng-hide="editdata[tabdata.id]">{{tabdata.name}}</div> <div ng-show="editdata[tabdata.id]"
<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>
这里我从数据库表中获取数据:
$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:{
}
})
};
}]);
问题是,当我点击编辑按钮时,它会被修改,但之后,当我编辑一些行数据时,它只更新静态页面中的数据。我还必须更新我的数据库表。那么怎么做呢
我必须使用服务函数和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调用。oops我让“fatch.php”和您的where说它是“fetch.php”;)那么现在该怎么办,先生..当我点击更新按钮时,它就会升级。但是我也必须更新我的数据库表。怎么做呢?你的$http方法帖子将把一些数据推送到你的服务中,然后在fetch.php中更新你的数据库。
$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;
});
})
}