Error with $http status 0

Hi,

i’m french and my english is not perfect, so sorry for that.

I have an issue with $http in my hybrid app (principle: it gets a list of business near you, with a call to an external api, mine, which return the list in json)

angular.module('starter.controllers', ['ionic', 'ngCordova'])
.controller('ListCtrl', function($scope, $cordovaGeolocation, $ionicLoading, $http, $window, Tabacs, Position) {
    $http.get("http://somejsonreturn.example/json.php").then(
        function(resp) {
        }, function(err) {
        });
}

with ionic serve on my computer it’s okay, the cross-domain request works, with ionic view on my Android device and on iOS device, it works too. But when i build an apk for Android an install it directly (on Android 4.4.2), it doesn’t work. I have an error status 0.

The domain called is mine, i have put at the start of the php file returning the json:

header("Access-Control-Allow-Origin: *");

I have also installed cordova-plugin-whitelist in my project and added <allow-navigation href="*" /> in the config.xml file. But nothing seems to work and i think i have made the turn of the solution i’ve found.

Any idea ?

Have you used Chrome remote debugging to your device plugged in your USB port?
If you haven’t, then this is a the best solution to know what’s going on.

header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
header('Access-Control-Allow-Headers: Authorization,Content-Type');

// CORS preflight request fix
if("OPTIONS" == $_SERVER['REQUEST_METHOD']) {
    http_response_code(200);
    exit(0);
}

Could you try the above code? I noticed that angular sends a request before the actual GET, using slim it gave problems to me, so i just forced it to respond with a HTTP200 code.

Make sure you allow content-type as well.

i still have status 0 returned

i’m going to try Chrome remote debugging to see if i can have more information.

Thx for your help, it’s very appreciated !

with Chrome remote debugging i have all the log, but i can’t find something usefull in it, maybe you will =)

If you need more details of the console, just ask

i’ve solved my issue, the directive were not applied. I’ve uninstalled ios and android from my project then reinstalled them and now it works fine !

Thanks all !

Hi,

What do you mean by “the directive were not applied”. I have the same problem, that is works in browser, works on ionic view, doesn’t work when apk installed on android

Cheers
A

I’m facing the same issue