我想在点击按钮时删除,但我的代码不起作用。这是我的代码 HTML
<tr class="row" ng-repeat="data in vm.mydata >
<td class="col-md-1"> <span>{{data.masp}}</span></td>
<td class="col-md-1"> <span>{{data.hangsx}}</span></td>
</tr>
<i class="fa fa-trash-o fa-2x" aria-hidden="true" ng-click="vm.delete(data.masp)"></i>
角
function dsController($http){
var vm =this;
$http.get('/project/app/server/data/data.php')
.then(onSuccess);
function onSuccess(response){
vm.mydata = response.data.records;
}
vm.delete = function(value){
$http({
method:'POST',
url:'/project/app/server/action/xoa.php',
data:({value:value}),
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(onSuccess,onError);
function onSuccess(){
$http.get('/project/app/server/data/data.php')
.then(function(data){
vm.mydata = data.data.records;
})
}
这里是php代码:xoa.php
//connect db
if(!empty($_POST['value'])){
$masp = $_POST['value'];
$sql = "DELETE FROM sanpham WHERE masp= '$masp'";
$result = mysqli_query($conn,$sql);
if($result){
echo 'OK';
} data.php
$rows = array();
if($result){
while($r = mysqli_fetch_assoc($result)) {
$rows[] = $r;
}
print '{"records":' .json_encode($rows) ."}";
我哪里错了。请帮助我
答案 0 :(得分:1)
在html中添加
vm.delete(data.masp,$index)
在js中你改变了
vm.delete = function(value,index)
{
method:'GET',
url:'/project/app/server/data/data.php?value=' +value
}
答案 1 :(得分:0)
尝试这样:
vm.delete = function (value) {
var Response = $http({
method:'POST',
url:'/project/app/server/action/xoa.php',
data:{value: JSON.stringify(value)},
});
return Response;
}