Http get request return status 0

i tried to get dynamic data from a external url using get method in http, it works fine in browser but when i run it from device the get request is not processed and returns status 0. CORS is also enabled. the controller is added below for reference

$scope.getData = function() {
        $http.get("http://somedomain")
            .success(function(data) {
                $scope.firstname = data;
                
            })
            .error(function(data, status,headers,config) {
                
      $scope.data = data;
      $scope.status = status;
      $scope.headers = headers;
      $scope.config = config;
            });
    };

why don’t you show the response, anyway i think it return a promise which you better handle it this way :

   var deferred = $q.defer();
      var url = "http://somedomain";
      $resource(url)
        .get(function(data) {
          deferred.resolve(data);
        }, function(response) {
          deferred.reject(response);
        });
      return deferred.promise;

I am sorry about not putting the response and thank you very much for the help. even after implementing what you said now i am not getting any output even in browser. the output is

status 0
response null
request null
data null

If is any help,
First use another servicer URL https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain see if you get data then try your service again and do this,

on your debugger (google dev-tools in my case) check your Network tab to see what is the response what code do you get when the data is requested e.g. code 200 is ok 401 file no found or 500 server error, then if the response is 200 then you should have a break point in before resolve the promise to check o the data retrieve, if the call is successful the break point will stop on the resolve part of the service but the response could be empty, so then check on the sever service.

Thank you very much for the input but same result its working fine in browser but when i run in device the output status 0

i have the same problem. I tried to compile the app with a old ionic version and it works fine. Maybe it is a ionic issue :frowning:

It is pretty hard to see the solution without the console errors if you have some screen shoots of the error, and the headers of the service call so we can see the output would be better. now if you don’t have the dev-tools to debug let me know I will point you in the right direction so look into it.

Now i think if any service that you call retrieves cero data, then is a network issue no the service itself, and this could be due to many problems on the network on the phone, but to be sure the info from the debugger is key to solve this puzzle

it is an issue on last release (1.0.0-rc5) released on 2015-04-27

where may I verify that information do you have a link, because all my services works perfect fine, and I would like to look into it before I mess the services that are working already.

service.js

 var all = function() {
        var users = [];
          var deferred = $q.defer();
          var url = "https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain";
          $resource(url)
            .get(function(data) {
                alert(data);
              deferred.resolve(data);
            }, function(response) {
              deferred.reject(response);
               alert("response");
            });
          return deferred.promise;
          };
      return {
        all: all
         
      }

controller.js

Chats.all().then(function(result) {
         $scope.chats = result;
     });

i am not able to debug in mobile device this request is working extremely ok with web browser

Which version are you using?
If you type ionic -v

Im using 1.3.20 as my version of ionic I started on this version two weeks o 3 ago

ok let me do a plunker that works for you and if still not getting data then you need to debug with a device and use the google developer tools to gather more info about the issue.

my version is 1.3.20

i have a same project … if i run it on ionic 1.3.22 it doesn’t works, if i run with an old version (1.2.8) it works fine

ok I made a sample for you I hope this helps

http://plnkr.co/edit/m74z5IbvBqBviH0IbLqe?p=preview

on the picture you will see data on the right hand side thats is proof the service is working and being displaying data on the html from the service

yes the problem is that on devide (android it doesn’t works)

Thank you for the updated code but still its not working in device. same as early

I’m running my app in android what kind of device and api are you using and remember to debug you need a device with 4.4 android version at lease and API 19 otherwise is impossible to debug .

i am using 4.2 android but when i run url in debug console none of the request are displaying