Basically what I am trying to do is ng-repeat records from my database, however, I am getting the following error 'SyntaxError: Unexpected token F in JSON at position 0'.
Here is my code:
HTML
<tr ng-repeat="x in data">
<td>{{x.songName}}</td>
<td>{{x.albumName}}</td>
</tr>
JS
$scope.loadTracks = function(){
$http.get('includes/functions/gettrack.php').success(function(data){
$scope.data = data;
})
}
PHP
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");
$data = array();
$sql = "SELECT * FROM tracks";
// Create a prepared statement
$stmt = mysqli_stmt_init($connection);
// Prepare the prepared statement
if (!mysqli_stmt_prepare($stmt, $sql)) {
// Error exists
die('Fatal error: service unavailable at this time');
} else {
// Run parameters inside the database
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if (mysqli_num_rows($result) > 0) {
// Check for results and assign results to array
while ($row = $result->fetch_assoc()){
$data[] = $row;
}
echo json_encode($data);
}
}
?>