0
所以我不斷從這張表中獲得第一個條目,但是裏面有三個(我發誓)。成功的警報響應和頁面將只返回第一個,所以我知道它沒有返回任何三件事。這是我的Javascript。
var itemSeletor = angular.module('itemIndex', []);
itemSeletor.controller('EventController', function($scope, $http) {
$http.get("itemIndexAjax.php")
.then(
function(response) {
// Success
$scope.events = [response.data];
//alert(response.data.events[0].name);
},
function(response){
// Error
alert("Error!");
console.error(response);
}
);
});
這裏是我的PHP腳本:
.....
$event_stmt = $mysqli->prepare("SELECT title, image, id FROM events");
if(!$event_stmt)
{
$sqlString = sprintf("SQL Query Prep Failed: %s\n", $mysqli->error);
echo json_encode(array("success" => false,
"message" => $sqlString));
exit;
}
$event_stmt->execute();
$event_stmt->bind_result($title, $image, $id);
$events = array();
while($event_stmt->fetch())
{
$this_event = array("name" => $title, "pic" => $image, "id"
=> $id);
array_push($events, $this_event);
}
$event_stmt->close();
echo json_encode(array("events" => $events));
exit;
?>
可能是NG-重複。
<span id="imageAndText" ng-repeat="event in events | filter:query">
<a href="event.php?id=" + "{{event.id}}">
<img src="{{event.pic}}" id="image" alt="Image Not Found">
<span class=eventTitle">
{{event.name}}
</span>
</a>
</span>
只是分配'$ scope.events = response.data.events ' –
謝謝,它工作。這樣的一個小錯誤 – JMizzle