I'm building a project with angular and php, I have a "file" table that I can upload files using only php. now I'm trying to retrieve all files details in my database. my error in the console is:
angular.js:13550 SyntaxError: Unexpected token < in JSON at position 0
at Object.parse (native)
can someone please check my code?
Php for displaying:
<?php header('Content-Type: text/html; charset=utf-8');
$connection = mysqli_connect('localhost','root','','hamatkin');
mysqli_query($connection,"SET character_set_client = utf8");
mysqli_query($connection,"SET character_set_connection = utf8");
mysqli_query($connection,"SET character_set_results = utf8");
if(!$connection){
die("couldnt connect".mysqli_error);
}
$query = "SELECT * FROM `file` ";
$queryResult = $connection->query($query);
$queryResult2 = array();
if($queryResult === FALSE) { die($connection->error); }
if( $queryResult->num_rows>0){
while($row = $queryResult->fetch_assoc()){
$queryResult2[] = $row;
}
}
$queryResult3 = json_encode($queryResult2);
echo json_encode($queryResult3);
?>
Controller:
"use strict";
angular.module('dataSystem').controller('allPriceOffersCtrl', function($scope,$route,$location,$http) {
$http({method:'GET', url:'api/customers-tab/get-all-priceOffers.php/'})
.then(function(response) {
var arr = JSON.parse(JSON.parse(response.data));
$scope.files = arr;
})
// This will log you the error code and trace, if there is an error.
.catch(function(err) {
console.log('err', err)
});
});
Html:
<div class="table-responsive">
<table class="customer-list table table-striped">
<thead>
<tr>
<th class="Column-Header">מספר</th>
<th class="Column-Header">משו</th>
<th class="Column-Header">שם מלא</th>
<th class="Column-Header">ת.ז./עוסק מורשה</th>
<th class="Column-Header">עיר</th>
<th class="Column-Header">כתובת</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in files">
<!-- <td>{{$index + 1}}</td> -->
<td>{{ x.id}}</td>
<td>{{ x.name}}</td>
<td>{{ x.mime}}</td>
<td> {{ x.size}} </td>
<td> {{ x.data}} </td>
<td> {{ x.created}} </td>
</tr>
</tbody>
</table>
</div>