我正在使用angular和php构建项目。当我尝试删除时,我有这个错误。该功能使所有信息都很好,我无法理解为什么它不起作用。有人可以帮忙吗?
$scope.delete = function( id)
{
var deleteFile = $scope.files[id];
var txt;
var r=confirm("למחוק?");
if(r==true){
// var params = $.param({"id":deletingId});
$http.post('api/customers-tab/delete-priceOffer.php',{id:deleteFile})
.success(function(data){
var arr=JSON.parse(JSON.stringify(data));
$scope.files = arr;
var arr2 = arr.split(",");
arr2.splice($index, 1);
$route.reload();
});
}
};
HTML:
<tr ng-repeat="x in files track by $index " >
<td>{{ x.created}}</td>
<td> {{ x.customer_id}} </td>
<td> {{ x.full_name}} </td>
<td> {{ x.city}} </td>
<td> {{ x.phone}} </td>
<td><a ng-click="delete($index)" value="Remove" class="btn btn-primary btn- active">מחיקה</a></td>
PHP:
<?php
header('Content-Type: text/html; charset=utf-8');
$connect=mysqli_connect("localhost", "root", "", "hamatkin");
include_once 'file.php';
mysqli_query($connect,"SET character_set_client = utf8");
mysqli_query($connect,"SET character_set_connection = utf8");
mysqli_query($connect,"SET character_set_results = utf8");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//$customer = new Customer();
$data = json_decode(file_get_contents("php://input"));
$x=$data->id;
$id = $data->id;
$del = "DELETE FROM file WHERE id=".$data->id;
mysqli_query($connect, $del);
// echo "delete Ok".$x;
$newURL = "/hamatkin/#/allPriceOffers";
header('Location: '.$newURL);
?>
答案 0 :(得分:1)
将$index
替换为id
,您正在传递$index
值但接受id
arr2.splice(id, 1);