【发布时间】:2017-03-01 12:49:26
【问题描述】:
您好,我正在尝试使用 php 和 AngularJS 获取特定用户的数据,但 AngularJS 没有在我的代码中添加参数我尝试了所有方法但没有任何效果,我不知道我使用 HTTP 有什么问题。获取过程
这是我的 JS 代码
var app = angular.module('myApp', ['ui.bootstrap']);
app.filter('startFrom', function() {
return function(input, start) {
if(input) {
start = +start; //parse to int
return input.slice(start);
}
return [];
}
});
app.controller('customersCrtl', function ($scope, $http, $timeout) {
$http.get('pages/modVehiclePayments/getPendingPO.php', {
params: {
source: link,
getvendornumber: user.phonenum
}
}).success(function(data){
$scope.list = data;
$scope.currentPage = 1; //current page
$scope.entryLimit = 50; //max no of items to display in a page
$scope.filteredItems = $scope.list.length; //Initially for no filter
$scope.totalItems = $scope.list.length;
});
$scope.setPage = function(pageNo) {
$scope.currentPage = pageNo;
};
$scope.filter = function() {
$timeout(function() {
$scope.filteredItems = $scope.filtered.length;
}, 10);
};
$scope.sort_by = function(predicate) {
$scope.predicate = predicate;
$scope.reverse = !$scope.reverse;
};
});
这是我的 PHP
$VendorNum = $_GET['getvendornumber'];
$query="SELECT * FROM tblvendors WHERE VendorNo='$VendorNum' AND statuscode='2'";
$result = $conn->query($query) or die($conn->error.__LINE__);
$arr = array();
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$arr[] = $row;
}
}
# JSON-encode the response
$json_response = json_encode($arr);
// # Return the response
echo $json_response;
【问题讨论】:
-
您是否已注销数据 ($scope.list)?是你所期望的,除了减去你期望的参数吗?
-
确保您的角度版本低于 1.6。
success不适用于 1.6 版以上 -
将 'console.dir(data) 或 console.log(data)' 放入成功函数并共享输出。
标签: javascript php angularjs