您好,我正在尝试对 filltext.com 服务器进行动态 $http 请求。代码:
<!DOCTYPE html>
<html lang="en" ng-app="App">
<head>
<meta carset="utf-8">
<title>Test</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
</head>
<body >
<div class="container" ng-controller="theController">
<div ng-repeat="person in people">
<input type="text" ng-model="person.fname">
<input type="text" ng-model="person.lname">
</div>
</div>
<script>
var app=angular.module('App', []);
app.controller('theController', ['$scope','$http',function($scope,$http){
$scope.getPeople=function(count){
$http.jsonp("http://www.filltext.com/?callback=JSON_CALLBACK&rows="+count+"&fname={firstName}&lname={lastName}").
success(function (data) {
$scope.people = data;
})
};
$scope.countSelection=10;
$scope.getPeople($scope.contSelection);
}]);
</script>
</body>
</html>
问题是当我尝试将 +count+ 添加到 $http.jsonp 字符串参数中时,我没有从 filltext.com 获取数据,但是当我静态写入 rows=5 时,它正在生成数据谢谢您的帮助:)