猿问

如何用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":"咸宁中路"

    }

}


森林海
浏览 1414回答 1
1回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答