Status 200 data Undefined Angularjs

Asked

Viewed 198 times

0

I’m building an angular application, where I give http.get in a url, the status comes 200, but the date comes empty. In the api where I built, I return the json array, and in the angular webservice, I apneas give http.get and the date returns me empty.

Follow my service code:

myApp.service('cinemas',function($http){

    return ({
        getList:getCinemasList
    });

    function getCinemasList(){
        return $http.get("http://api.localhost:8080/movie/204").then(function(response){
            console.log(response.data);
        });
    }
});
  • If you call the link in the browser returns a certain json?

  • yes, in the browser returns.

  • Press F12, go to the network tab, take your Request and check the content of Sponse, if the server is sending you the return.

1 answer

0

Try something like that:

.factory('MeuService', ['$http', '$q', function($http, $q) {
 var URL = "MinhaUrl";
return {
    getCinemas: function(){
     var deffered = $q.defer();
     $http({
          method: 'GET',
          url: URL
        }).then(function successCallback(response) {
            deffered.resolve(response.data);
          });
        return deffered.promise;
    }
}
}])
  • I can access, from all my servers, I have a shaman running and I can access, I have an external server running and I can access, but this server I’m trying to access is a Server, and I’m running via Rtisan, I tested my service and it was able to get the data from all servers, except the one running via Artisan

  • It may be CORS, have a look: http://stackoverflow.com/questions/23823010/how-to-enable-cors-in-angularjs

  • I don’t quite understand what this is for. I wanted to understand why it works on my normal localhost network, and does not work on the Laravel Artisan route, whether it is local like any other server like xampp,wamp,etc..

  • Cors is a security constraint, and the server may be blocking the request, so it does not display the expected result. see if this link resolves: http://stackoverflow.com/questions/20792134/allowing-cors-in-artisan-serve

  • In the browser log some msg appears?

  • null value appears

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.