我的HTTP没有加载数据,我不知道为什么。请有人帮帮我吗?我尝试了两个网络托管,我的一个,我得到了一个“访问控制 - 允许 - 来源”#39;标头出现在请求的资源上。'错误,所以我使用了Myjson服务器,现在我没有收到任何错误,但没有任何负载,请有人帮忙吗?
这是我的json文件:
{
"response1": [
{
"announcement_name": "Example Message 1"
},
{
"date": "15/05/2015"
},
{
"message": "Example Message 1"
}
],
"response2": [
{
"announcement_name": "Example Message 2"
},
{
"date": "15/05/2015"
},
{
"message": "Example Message 2"
}
]
}
HTML:
<body ng-app="Announcement">
<ion-view view-title="Announcements">
<ion-pane>
<ion-header-bar class="bar-positive">
<h1 class="title">Pull To Refresh</h1>
</ion-header-bar>
<ion-view view-title="Announcements">
<ion-content ng-controller="Controller">
<ion-refresher on-refresh="doRefresh()">
</ion-refresher>
<ion-list>
<ion-item ng-repeat="item in items" ng-click="getData()">
<div class="list card">
<div class="item item-divider">{{announcement_name}} - {{date}}</div>
<div class="item item-body">
<div>
{{message}}
</div>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
使用Javascript:
.controller('Controller', function($scope, $http) {
$scope.items = [1,2,3];
$scope.doRefresh = function() {
$http.get("https://api.myjson.com/bins/1sdnx")
.success(function(data) {
$scope.announcement_name = data.announcement_name;
$scope.date = data.date;
$scope.message = data.message;
})
.finally(function() {
// Stop the ion-refresher from spinning
$scope.$broadcast('scroll.refreshComplete');
});
};
});
答案 0 :(得分:0)
实际响应数据出现在响应的data
对象上。
.controller('Controller', function($scope, $http) {
$scope.items = [1,2,3];
$scope.doRefresh = function() {
$http.get("https://api.myjson.com/bins/1sdnx")
.success(function(result) {
console.log(result);
console.log(result.data);
$scope.announcement_name = result.data.announcement_name;
$scope.date = result.data.date;
$scope.message = result.data.message;
})
.finally(function() {
// Stop the ion-refresher from spinning
$scope.$broadcast('scroll.refreshComplete');
});
};
});