4

I'm trying to do a simple ajax request, and the response status is "200, ok", using the Postman I can validate my JSON, and looks fine, and the header is ok too ... but $http aways fail. I try to put a very simple JSON and aways have the same result. The solutions doesn't work for me

My ANGUJAR JS request:

$http.get('http://127.0.0.1:8000/produto/')
            .then(function successCallback(response) {
                console.info('success =)');
                console.info(response);
                // this callback will be called asynchronouslywhen the response is available

            }, function errorCallback(response) {
                // called asynchronously if an error occurs
                // or server returns response with an error status.
                console.info('fail =(');
                console.info(response);
            });

My JSON result, but with a simple response like [] I had the same problem :

[{"id":1,"nome":"NOME UPD","doce":"1","deleted_at":null,"created_at":"2016-04-26 13:23:49","updated_at":"2016-04-26 13:23:49"},{"id":2,"nome":"NOME UPD","doce":"1","deleted_at":null,"created_at":"2016-04-26 13:24:25","updated_at":"2016-04-26 13:24:25"},{"id":3,"nome":"NOME UPD","doce":"1","deleted_at":null,"created_at":"2016-04-26 13:24:46","updated_at":"2016-04-26 13:24:46"},{"id":4,"nome":"NOME UPD","doce":"1","deleted_at":null,"created_at":"2016-04-26 13:25:16","updated_at":"2016-04-26 13:25:16"},{"id":5,"nome":"NOME UPD","doce":"1","deleted_at":null,"created_at":"2016-04-26 13:28:06","updated_at":"2016-04-26 13:28:06"},{"id":6,"nome":"NOME UPD","doce":"1","deleted_at":null,"created_at":"2016-04-26 18:05:15","updated_at":"2016-04-26 18:05:16"},{"id":7,"nome":"NOME UPD","doce":"1","deleted_at":null,"created_at":"2016-04-26 18:52:42","updated_at":"2016-04-26 18:52:43"},{"id":8,"nome":"NOME UPD","doce":"1","deleted_at":null,"created_at":"2016-04-26 20:29:43","updated_at":"2016-04-26 20:29:43"}]

Tanks a lot.

Community
  • 1
  • 1
cmnardi
  • 1,051
  • 1
  • 13
  • 27

1 Answers1

1

My problem was with CORS access. the server don't allow requests from my AngularJS application ...

I enable my apache to allow access

a2enmod headers
sudo nano /etc/apache2/sites-available/default

In the file, put inside the tag

Header set Access-Control-Allow-Origin "*"

And restart the apache

See. http://www.mechonomics.com/enabling-cors-cross-origin-resource-sharing-for-apache2-on-ubuntu-12-04/

Tanks

cmnardi
  • 1,051
  • 1
  • 13
  • 27