HTTP GET over angular and also XMLHttpRequest throws strange error on cordova device

We do a simple GET over angulars HTTP library to an url like
If we run this with ionic serve every thing is fine, but if we run this with ionic cordova emulate android we get a strange error. We tried also to run this on a new clean ionic project, we have the same error.

We test it to make a plain XHR call, and there we get also errors. This is an example of our call:
var xhr = new XMLHttpRequest();'POST', '', true); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { console.log(xhr.responseText) } }; xhr.withCredentials = true; xhr.send('{}');

The only thing a new about this error, the POST is never send, the error is on client side. And as mentioned before if I do the same thing in ionic serve anything is working fine.

in my config.xml the access origin is configured like this
<access origin="*" />

Some ideas?

We found out, this is also working on ionic cordova run, so probably in the last few day we tested this only on device and not on emulator. So the question is, why this is working on device and on ionic serve but not on emulator?

Hmm this remembers me a problem I had two years before with Ionic 1. I resolved the problem when I added this lines to my config.xml

<access origin="*" />
<access origin="http://*" />
<access origin="https://*" />

… or simmilar. I had to explicitly enable usage of http and https protocolls (allthough the file protocoll, tel protocoll, any one I used in the app). Perhaps this could help …

You could allthough have a look at this: <access origin="tel:*" launch-external="yes" /> not worked IOS

access origin or allow-intent? The second one is allready there

<content src="index.html" />
<access origin="*" />
<allow-navigation href="http://ionic.local/*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />

The strange thing anything was working fine until this morning, the first thing I thought I did something wrong today. But this is also not working anymore on a clean project so :expressionless:

Here’s the WhiteList doc. I think it’s access origin you look for.

As expected the workaround with the the access origin to http and https doesn’t work.

I found out, If we run it on device there is no error and anything is working fine.

So the problem is only on emulator and probably in the last few days we test this only on device and not emulator.

So the question is why this is working on ionic serve and ionic cordova run but not emulate?

Could be the problem setted firewall rules? Do you have root access and setted ip tables on your emulated device? Perhaps there are optional ways with adb to set routes to your network. Did you allthough looked for your proxies you are able to set in Ionic1 projects?

I never used the emulater. And I don’t know if you are able to set proxies on Ionic2 projects … I just had this thoughts about your issue …

If solve it, let us know :slight_smile: Sorry for poor English.

Edit: OMG!!!

I found the solution, I had the problem because the emulator was offline!!! :expressionless:

Offline does mean, the Data status in Cellular in emulators Extended controls was set to Unregistred (off)


@donotsue thx for your hint! At the end I could figured out because I tested the urls in the browser!

I have a new similar error on release builds, perhapse someone can help. Have a look on this new post thx

1 Like