Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularjs $http returns error 0
    text
    copied!<p>Alright so I have an AngularJS application with Laravel 4 as a backend. The way I want to develop is by running Laravel on a seperate server (via artisan serve) and angular on a seperate one with yeoman assembling all that grunt server for me.</p> <p>However after trying to get data from the Laravel 4 backend (which serves as a REST api) via Angulars $http all I get is a 0 error message. Here's my code:</p> <p>Angular REST service:</p> <pre><code>app.factory('RestService', function($http){ var restUrl = 'http://localhost:8000/api/v1/tags';//&lt;-- rest api served with php artisan return { getResource: function(){ return $http({method: 'get', url: restUrl}) } } }); </code></pre> <p>Angular controller:</p> <pre><code>app.controller('TagCtrl', function($scope, RestService){ $scope.getTagList = RestService.getResource() .success(function(){ console.log('Success!'); }) .error(function(data, status, headers, config){ console.log(data);//&lt;--returns nothing console.log(status);//&lt;--returns 0 console.log(headers);//&lt;-- returns function console.log(config);//&lt;-- returns object }); }); </code></pre> <p>And here is my Laravel 4 routes:</p> <pre><code>Route::get('tags', function(){ return "This is a temporary message to test routing"; }); </code></pre> <p>Now as all this works if I don't use grunt serve and artisan and put it all in the same folder (angular inside laravels public folder etc.) which I intend to do when I move to production but because I want to minify and do other stuff with grunt before that I want to keep those elements seperate for now. </p> <p>With some googling I assume the problem is with CORS (cross origin request) but I can't understand how to resolve the issue in this setting.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload