如何用angular获取json文件

在自己本地的服务器上运行,但是chrome下一直报错,

angular.min.js:103XMLHttpRequest cannot load localhost:80/angular/data.php. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.


这是first.html中的代码

var app=angular.module('myApp',[]);
app.controller('myCtrl',function($scope,$location,$timeout,$http){
    $http.get("http://localhost/angular/data.php")
         .success(function(response){$scope.data=response.records;});
})
        
这是data.php中的,

{
"name":"张春林",
"age":"20",
"school":{
    "name":"八十三中",
    "location":"咸宁中路"
    }
}
阅读 4.9k
3 个回答

跨域了,配个反向代理啥的。要不用jsonp也行。

这就是个跨域问题,配置一下

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题