私はangularjsを使用してmysqlデータベースからデータをロードします。where句を使用してangularjsを使用してデータベースからデータを取得します
これはアプリケーションの動作方法です。 ユーザーのログインとそのユーザー名はCookieに格納されます。 このユーザ名は、ホーム・ページ
に表示されている私は、これは私のPHPのスクリップでこの値を取得し、where句
で、ユーザ名に基づいてテーブルからデータをフェッチするためにangularjsを通じてPHPスクリプトに渡したい
<?php
include_once 'connect.php';
$data = json_decode(file_get_contents("php://input"));
$statement = $conn->prepare('SELECT MessageId, Subject, MessageContent, CONCAT(Date, " , ", Time) AS Date, FromUser, ToUser, MessageType, File, FileName FROM messages where MessageType = "Broadcast" or ToUser=:UserName order by MessageId desc');
$statement->execute(array(
'UserName' => $data->UserCookie
));
while($row = $statement->fetch()) {
$data[] = $row;
}
print json_encode($data);
?>
は、これはこれは私のホーム・ページ
である私の角度スクリプトvar app = angular.module('Library', ["ngCookies"]);
app.controller('LibraryController', function($scope, $http, $interval, $cookies) {
//get cookie user name
$scope.UserCookie = $cookies.get('cookieUserName');
//set cookie user name
$scope.setCookie = function(val){
$cookies.put('cookieUserName', val);
}
//display messages
$scope.loadMessages = function() {
$http.post('selectMessages.php',{'UserName': $scope.UserCookie})
.success(function(data) {
$scope.Messages = data;
})
}
//display messages at an interval of 1 seconds
$interval($scope.loadMessages, 1000);
});
です
<!DOCTYPE html ng-app="Library" ng-controller="LibraryController">
<html>
<head>
<title></title>
</head>
<body ng-init="loadMessages()">
<div class="form-group">
<label for="Subject">User</label>
<input type="text" ng-model="UserCookie" name="UserCookie" class="form-control" id="UserCookie" required="required"></input>
</div>
<input type="search" class="form-control" ng-model="searchMessage" placeholder="Search"> <br />
<table class="table table-hover">
<thead>
<tr>
<th>Message (Sender)</th>
</tr>
</thead>
<tbody>
<tr ng-click="selectMessage(message.MessageId, message.MessageContent, message.Date, message.Time, message.File)" onclick="showCommentDialog()" style="font-size: 16px" ng-repeat="message in Messages | filter:searchMessage | limitTo:20">
<td>{{ message.Subject }} (<span style="color:green"> {{ message.FromUser }})</span></td>
<td>
<button class="btn btn-success" ng-click="selectMessage(message.MessageId, message.MessageContent, message.Date, message.Time, message.File)" onclick="showCommentDialog()" > view </button>
</td>
</tr>
</tbody>
</table>
</body>
</html>
これは私が得るエラーですError from browser console どうしたらいいですか?助けて!
AJAX要求が何であるかを、あなたのコンソールのネットワークセクションでのチェックイン、そのURLとそれが(それは本当にselectMessages.phpスクリプトに達しない)、右ですか? – krasipenkov
ネットワークセクションにチェックが入っているときは、私が実際に理解していないエラーメッセージです。助けてもらえますか? – Franklin
最初はエラーメッセージを表示しないことに申し訳ありません。これは私が意味していたものです。ネットワークのセクションでチェックされているときは、私が実際に理解していないエラーメッセージです。助けてもらえますか?注意:未定義のプロパティ:stdClass :: $ UserCookieのC:\ xampp \ htdocs \ LibraryApp \ selectMessages.php(16行目)致命的なエラー:C:\ xampp \ htdocs \ LibraryApp \ selectMessages.phpの配列としてstdClass型のオブジェクトを使用することはできませんon line 20 – Franklin