私はAngularJSで簡単な検索エンジンを作ろうとしています。クライアントとサーバーの間の通信に問題があります。私はw3schoolsガイドhttp://www.w3schools.com/angular/angular_sql.aspに従おうとしています。ここでAngularJSでの簡単なデータベース検索エンジン
はhome.php体です:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
</script>
</head>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<table>
<tr ng-repeat="x in names">
<td>{{ x.Name }}</td>
</tr>
</table>
</div>
<script>
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);});
});
</script>
、ここではserver.phpというのです。
<?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->query("SELECT * FROM associations");
$outp = "";
while($donnees = $query->fetch())
{
if ($outp != "") {$outp .= ",";}
$outp .= '{"Name":"' . $donnees["nom"] . '"}';
}
$outp ='{"records":['.$outp.']}';
$conn->close();
echo($outp);
?>
しかし、私はこのエラーをgettinのよ:angular.js:12520SyntaxError: JSONの予期しないトークンの位置0の、任意のアイデアですか?ここで
'server.php'にエラーがないことを確かめてください。私には1つあります。 – Rayon
{{x.Name}}で白いページが表示されています。 –
'error_reporting(2);'をセットし、テスト.. – Rayon