Error with angularJS with $ http.get

1

I'm trying to get some data via WS (Web Service), but when I ask to return in my app it gives this error:

  

In 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

But when I try to fetch via console it returns normally.

var App = angular.module('App', ['ionic']);

//listar clientes via ws somente ativos

App.get('ListaCtrl', function($scope, $http){
   $http.post('http:// meu url da ws').
       success(function (data) {
           $scope.ret = data;
   });
});
    
asked by anonymous 05.05.2015 / 20:06

1 answer

2

When you are consuming data from other domains, you must have access to external domains in WS to make it work. By default, browsers and servers block non-domain access to prevent intrusions.

Another method that can be seen is to make the request sent in JSONP format, which in most WebServices is already released as default ... In the case of AngularJS used above (note by $http.get ) you can do something like the example below:

$http.get({
  url : '/api/contest/submit.action', 
  data : { params: $param, responseType: 'jsonp' }
});

NOTE Here is a solution, I have not tested it yet but should probably work ...

Enable CORS with AngularJS

    
05.05.2015 / 20:40