Ajax requests in Android


#1

I’m trying to test the my AJAX scenario android using ionic…

First I used ionic serve …which was successful

Then I tried ionic run android…

I was able to successfully build the .apk file and install and launch on an android emulator. However, I seem to be having trouble communicating with external uri via ajax calls

I’m running Cordova 3.5 and I believe all my permissions are set(I’m using all default configurations so far)

Not sure what the problem is as I can surf the net with the emulator browser


#2

I don’t have an answer, unfortunately, but we’re experiencing the same issue. Has it ever worked for you?

We see this only when using Google Play .apk on Android (iOS works fine). This was working on a previously submitted version Android of our app, but now the initial AJAX call (a login in our case) fails immediately with an HTTP status of ‘0’ indicating that it’s probably not submitting at all.

In our case after removing the Android platform and adding it back, we were able make AJAX calls with an apk installed directly on an Android device (emulator is too slow to be useful) but still now on an apk available for the store.


#3

I agree with @lutherkent. I came across this error and so many googling around couldn’t save me. There were suggestions to make the request not asynchronous async:false. Others said it has to be true. Some say add cache:false. Others say append a unique timestamp to the request url. None of these options worked for me. I simply removed the platform; ionic platform remove android, and add it again: 'ionic platform add android. It failed the first time [turned out there was a plugin that was not properly installed]. I proceeded to remove it since I had no need of it again.

After I added the platform again, and did a build, everything was ok again.


#4

I think this has something to do with the server that you’re communicating with. They have to have CORS enabled in order to handle cross-domain requests, which is basically them replying with a header saying all is good for cross-domain calls. Otherwise you will have to use ‘jsonp’ to send your data via GET.

http://www.w3.org/TR/cors/