错误Access-Control-Allow-Origin使用Angular.js和API与Laravel5.1

时间:2015-07-22 21:15:49

标签: javascript php angularjs laravel-5.1

我正在使用Laravel 5.1和Angular.js开发一个应用程序,当我尝试连接时,我有下一个错误:

XMLHttpRequest cannot load http://localhost:8000/university. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.

我有下一个角度代码:

angular.module('clientApp')

.controller('UniversityCtrl', function ($scope, $resource) {
  Universities = $resource("http://localhost:8000/university/:id",{id: "@id"});

  $scope.Universities = Universities.query();
});

我的观点:

<table>
 <thead>
   <tr>
     <th>University</th>
     <th>Address</th>
     <th>Phone</th>
   </tr>
</thead>

 <tbody>
   <tr ng-repeat="Universities in University">
      <td>{{University.name}}</td>
   </tr>
 </tbody>
</table>

和我的Laravel代码:

    public function index()
{
    $universities = university::all();
    return response()->json(
        $universities->toArray()
    );
}

谢谢:D

1 个答案:

答案 0 :(得分:0)

由barryvdh单独安装此package