Javascript 通过远程AJAX请求获取和显示对象
我试图显示一个通过AJAX远程获取的对象。我当前遇到的错误是:Javascript 通过远程AJAX请求获取和显示对象,javascript,jquery,ajax,angularjs,ionic-framework,Javascript,Jquery,Ajax,Angularjs,Ionic Framework,我试图显示一个通过AJAX远程获取的对象。我当前遇到的错误是: ReferenceError: $stateParams is not defined 以下是我在services.js中看到的内容: .factory('Games', function() { var games = $.ajax({ "url":"https://www.kimonolabs.com/api/dc6n4edu?apikey=[APIKEY]&callback=kimonoCallback"
ReferenceError: $stateParams is not defined
以下是我在services.js中看到的内容:
.factory('Games', function() {
var games = $.ajax({
"url":"https://www.kimonolabs.com/api/dc6n4edu?apikey=[APIKEY]&callback=kimonoCallback",
"crossDomain":true,
"dataType":"jsonp"
});
return {
all: function() {
return games;
},
get: function(gameID) {
// Simple index lookup
return games[gameId];
}
}
});
.controller('AccountCtrl', function($scope, Games) {
console.log("test in controller");
$scope.game = Games.get($stateParams.gameId);
});
<ion-list>
<ion-item ng-repeat="item in items">
Hello, {{item}}!
</ion-item>
</ion-list>
以下是我在controller.js中的内容:
.factory('Games', function() {
var games = $.ajax({
"url":"https://www.kimonolabs.com/api/dc6n4edu?apikey=[APIKEY]&callback=kimonoCallback",
"crossDomain":true,
"dataType":"jsonp"
});
return {
all: function() {
return games;
},
get: function(gameID) {
// Simple index lookup
return games[gameId];
}
}
});
.controller('AccountCtrl', function($scope, Games) {
console.log("test in controller");
$scope.game = Games.get($stateParams.gameId);
});
<ion-list>
<ion-item ng-repeat="item in items">
Hello, {{item}}!
</ion-item>
</ion-list>
以下是我在选项卡account.html中的内容:
.factory('Games', function() {
var games = $.ajax({
"url":"https://www.kimonolabs.com/api/dc6n4edu?apikey=[APIKEY]&callback=kimonoCallback",
"crossDomain":true,
"dataType":"jsonp"
});
return {
all: function() {
return games;
},
get: function(gameID) {
// Simple index lookup
return games[gameId];
}
}
});
.controller('AccountCtrl', function($scope, Games) {
console.log("test in controller");
$scope.game = Games.get($stateParams.gameId);
});
<ion-list>
<ion-item ng-repeat="item in items">
Hello, {{item}}!
</ion-item>
</ion-list>
你好,{{item}}!
控制器函数中缺少$stateParams
值。。。但我确实认为您应该考虑使用$http
服务或资源
.controller('AccountCtrl', function($scope, $stateParams, Games) {
console.log("test in controller");
$scope.game = Games.get($stateParams.gameId);
});
$ajax是什么类型的调用?get post?它是一个get,返回与ui路由器相关的对象+数组$stateParams。你能给出app.js代码来定义你的导航路线吗。config(function($stateProvider,$urlRouterProvider){$stateProvider.state……$stateProvider//为tabs指令设置一个抽象状态。state('tab',{url:'/tab',abstract:true,templateUrl:'templates/tabs.html})我正在使用Ionic Framework的示例tabs应用程序