0

Hello I've built a Cordova application which gets data from an Angular webservice like this:

var req = {
        method: 'POST',
        url: 'http://mywebservice.com',
        headers: {
            'Content-Type': 'application/json; charset=utf-8'
        },
        data: { data},
        crossDomain: true
    };

    $http(req).

        success(function(data, status, headers, config) {

            callback(data);
        }).

        error(function(data, status, headers, config) {
            console.log("error: "+JSON.stringify(status));
    });

In a Ripple emulator or the iOS emulator everything works great and the data is shown. But if I run the app on a device I get no data from the webservice.

In my config.xml I have the tag:

<access origin="*"/>

to give access to the internet. Also I found these permission in the AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

So I don't understand why I'm getting no data shown if everything works perfectly in the emulator.

Cordova Version 4.3.0.

Update: Well if I run the app on a iOS device it also works. This problem only appears if I run it on a android device.

Kingalione
  • 4,237
  • 6
  • 49
  • 84

1 Answers1

0

Where is your webservice Running ? I assume that it is running on your proper machine.

If yes, this explain that you get a CORS issue as on localhost, you are simply bypassing that fact.

To resolve that point, you need to update your webserver to enable CORS queries.

aorfevre
  • 5,034
  • 3
  • 21
  • 51