猿问

请问使用angular中的$http报错是为什么

<!DOCTYPE html>
<html ng-app="demo2">
<head>
    <meta charset="UTF-8">
    <title>表格</title>
    <script src="js/angular.js"></script>
    <script src="js/biaogeTest.js"></script>
</head>
<body>
    <div ng-controller="customersCtrl">
        <table>
            <tr ng-repeat="x in names">
                <td>{{ x.Name }}</td>
                <td>{{ x.Country }}</td>
            </tr>
        </table>

    </div>
</body>
</html>
/**
 * Created by tongwii on 2017/7/4.
 */
var app = angular.module('demo2',[]);
app.controller('customersCtrl',function ($scope,$http) {
    $http.get("http://www.runoob.com/try/angularjs/data/Customers_JSON.php")
        .then(function (result) {
            $scope.names = result.data.records;
        });
});

错误信息

biaogeTest.html:1 XMLHttpRequest cannot load http://www.runoob.com/try/angularjs/data/Customers_JSON.php. 
No 'Access-Control-Allow-Origin'
 header is present on the requested resource. Origin 'http://localhost:63342' 
is therefore not allowed access.
angular.js:14525 Possibly unhandled rejection: {"data":null,"status":-1,"config":{"method":"GET",
"transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback",
"url":" 
"headers":{"Accept":"application/json, text/plain, */*"}},"statusText":""}
(anonymous) @ angular.js:14525

在网上查是说ajax跨域,请问这个如何解决?

呆呆呆
浏览 4285回答 0
0回答
随时随地看视频慕课网APP
我要回答