范围为

时间:2017-07-20 16:57:38

标签: php angularjs ajax api

尝试使用php文件将数据发布到api但它似乎不起作用。我正在使用角度1.2.9

 $scope.submit = function () {


var submitedData = {
  name:  $scope.choise.name,
  image: $scope.choise.image,
  songs: $scope.choices
 }

   $http.post("api/playlist.php",submitedData).success(function(submitedData){
    $scope.choices, $scope.choise.name, $scope.choise.image = submitedData;
   });
    console.log(submitedData);
  }
我得到了 通知:未定义的索引:在 17 C> C:\ xampp \ htdocs \ Music-Player \ api \ playlist.php 中键入>
注意 C:\ xampp \ htdocs \ Music-Player \ api \ playlist.php 28
中的未定义索引:id > { “成功”:假}

这是php文件

        case 'POST':
          $okresult = false;
            $data = NULL;
            $p =& $_POST;
            if( !empty($p['name']) && !empty($p['image']) && !empty($p['songs']) && is_array($p['songs']) ) {                   
                $okresult = true;
                $c = count($p['songs']);
                for($i=0;$i<$c && $okresult;$i++) {
                    $okresult = !empty($p['songs'][$i]['name']) && !empty($p['songs'][$i]['url']);
                }               
                if($okresult) {
                    $stmt = $conn->prepare("INSERT INTO playlists(name,image,songs) VALUES(:name, :image, :songs)");
                    $stmt->execute(array(
                        'name' => $p['name'],
                        'image' => $p['image'],
                        'songs' => json_encode($p['songs'],TRUE)
                    ));
                    $data = [
                        'id' => $conn->lastInsertId()
                    ];
                }               
            }
            response($okresult,$data);
        break;
        default:
            fail(404);
        break;
    }   
}

0 个答案:

没有答案