Ich möchte löschen, wenn Sie auf die Schaltfläche klicken, aber mein Code funktioniert nicht. Hier ist mein Code htmlZeile in der Datenbank löschen mit angular js
<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>
Winkel
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;
})
}
und hier ist PHP-Code: 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) ."}";
Wo ist falsch. Pls help me
Warum sind Sie eine HTTP POST-Anforderung stellt eine zum Löschen Objekt? Sie sollten HTTP DELETE verwenden. –
Daten werden aus der Tabelle entfernt –
Ihr vorstehender Code scheint in Ordnung zu sein. Können Sie bitte den Fehler teilen, wenn Sie irgendwelche bekommen? Oder bestätigen Sie bitte aus db-Tabelle, dass Datensatz gelöscht oder nicht? –