Javascript 使用$http.jsonp检索jsonp时出现问题
代码: 当我通过浏览器中的url时,我可以在尝试打开它时看到所有对象,例如: 但我的代码中似乎没有让它工作,我遗漏了什么吗Javascript 使用$http.jsonp检索jsonp时出现问题,javascript,json,ionic-framework,application-icon,Javascript,Json,Ionic Framework,Application Icon,代码: 当我通过浏览器中的url时,我可以在尝试打开它时看到所有对象,例如: 但我的代码中似乎没有让它工作,我遗漏了什么吗 angular.module('ionicApp', ['ionic']) .controller('MyCtrl', function($scope, $http) { $scope.items = []; $http.jsonp('cmaden.pythonanywhere.com/api/v1/today/?format=jsonp').suc
angular.module('ionicApp', ['ionic'])
.controller('MyCtrl', function($scope, $http) {
$scope.items = [];
$http.jsonp('cmaden.pythonanywhere.com/api/v1/today/?format=jsonp').success(function (data) {
$scope.items = data;
});
});
将“https://”添加到url的前面。您还需要一个回调。请参见下面的示例
angular.module('ionicApp', ['ionic'])
.controller('MyCtrl', function($scope, $http) {
window.callback = function(data) {
$scope.items = data
}
$scope.items = [];
$http.jsonp('https://cmaden.pythonanywhere.com/api/v1/today/?format=jsonp');
});