Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用AngularJS从其他域(没有回调函数)加载JSON数据对象_Json_Angularjs - Fatal编程技术网

如何使用AngularJS从其他域(没有回调函数)加载JSON数据对象

如何使用AngularJS从其他域(没有回调函数)加载JSON数据对象,json,angularjs,Json,Angularjs,在AngularJS中是否可以不使用回调函数加载JSON数据?如果我手动下载json文件并将url更改为“phones/phones.json”。在jQuery中,这是可能的 回答:谢谢!我将“raw.githubusercontent.com/angular/angular phonecat/master/app/phones/phones.json”更改为“rawgit.com/angular/angular phonecat/master/app/phones/phones.json” 看

在AngularJS中是否可以不使用回调函数加载JSON数据?如果我手动下载json文件并将url更改为“phones/phones.json”。在jQuery中,这是可能的

回答:谢谢!我将“raw.githubusercontent.com/angular/angular phonecat/master/app/phones/phones.json”更改为“rawgit.com/angular/angular phonecat/master/app/phones/phones.json”


正如Jared所说,这是服务器端的问题。

问题不在于客户机,而在于服务器

这实际上是指向不同URL的同一代码,它可以工作


我认为您需要HTTP请求的响应包含“Access Control Allow Origin”头,该头的值为“*”,以便从另一个站点访问内容。如何操作取决于您的服务器技术。

您是否检查了
$http.jsonp
。还要检查一下你到底想做什么?@Jack我试过$http.jsonp。我想使用其他网站的json数据。我使用$http.jsonp编辑了另一个示例。
var phonecatApp = angular.module('phonecatApp', []);

phonecatApp.controller('PhoneListCtrl', ['$scope', '$http',
    function ($scope, $http) {
    $http.get('https://raw.githubusercontent.com/angular/angular-phonecat/master/app/phones/phones.json').success(function(data) {
        $scope.phones = data.splice(0, 5);
    });

    $scope.orderProp = 'age';

}]);
var phonecatApp = angular.module('phonecatApp', []);

phonecatApp.controller('PhoneListCtrl', ['$scope', '$http',
    function ($scope, $http) {
    $http.get('https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS').success(function(data) {
        $scope.phones = data;
    });

    $scope.orderProp = 'age';

}]);