【问题标题】:$index is not defined error when i try to delete当我尝试删除时,$index 未定义错误
【发布时间】:2016-08-11 13:19:40
【问题描述】:

我正在用 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);
?>

【问题讨论】:

  • 您将$index 传递给您的函数。在函数中,您将其用作id
  • 请准确输入您的代码部分,
  • @AranS 好的,谢谢!不再有错误....现在其他错误:可捕获的致命错误:stdClass 类的对象无法转换为字符串
  • @VijayPatel 我不明白什么代码
  • 对不起!我理解你的问题的错误!

标签: php angularjs json angularjs-directive


【解决方案1】:

$index 替换为id,您正在传递$index 值但接收id

arr2.splice(id, 1);

【讨论】:

  • 好的,谢谢!不再有错误....现在其他错误:可捕获的致命错误:stdClass 类的对象无法转换为字符串
猜你喜欢
  • 2015-06-27
  • 1970-01-01
  • 2014-05-31
  • 2020-03-26
  • 2016-01-20
  • 1970-01-01
  • 2022-01-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多