title: Simple database search engine in AngularJS
body: <p>i'm trying to make a simple search engine in AngularJS. I have an issue with the communication between my client and my server. I'm trying to follow the w3schools guide <a href="http://www.w3schools.com/angular/angular_sql.asp" rel="nofollow">http://www.w3schools.com/angular/angular_sql.asp</a>.</p>
  
  <p>Here's home.php body :</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8" /&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"&gt;      
  &lt;/script&gt; 
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;div ng-app="myApp" ng-controller="customersCtrl"&gt; 
  &lt;table&gt;
      &lt;tr ng-repeat="x in names"&gt;
          &lt;td&gt;{{ x.Name }}&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
  var app = angular.module('myApp', []);
  app.controller('customersCtrl', function($scope, $http) {
      $http.get("server.php")
      .then(function (response) {$scope.names = JSON.parse(response.data.records);});
  
  });
  
  &lt;/script&gt;
  </code></pre>
  
  <p></p>
  
  <p>and here's server.php :</p>
  
  <pre><code>&lt;?php
  header("Access-Control-Allow-Origin: *");
  header("Content-Type: application/json; charset=UTF-8");
  error_reporting(2);
  
  $conn = new PDO('mysql:host=localhost;dbname=mygaloo;charset=utf8', 'root',    ''); 
  $result = $conn-&gt;query("SELECT * FROM associations"); 
  $outp = "";
  
  while($donnees = $query-&gt;fetch()) 
  {
      if ($outp != "") {$outp .= ",";}
      $outp .= '{"Name":"'  . $donnees["nom"] . '"}';
  }
  
  $outp ='{"records":['.$outp.']}';
  $conn-&gt;close();
  
  
  echo($outp);
  ?&gt;
  </code></pre>
  
  <p>However, i'm gettin this error : <strong>angular.js:12520SyntaxError: Unexpected token u in JSON at position 0</strong>, any idea ?</p>