AJAX CORS requests stopped working in latest CORDOVA / IONIC v2 beta4 in ANDROID


I’m about to cry :frowning: - spent full day without any result.

What I did is just updated ionic_v2 to beta4 in my project following dependencies generated by ionic start command.

####After upgrade:

  • In browser all good,
  • In iOS all good
  • In android not good - all ajax request doesn’t work.

Actually CORS requests are not happening - it goes directly to POST by skipping OPTIONS.

Console log error for ajax request:


Anyone have any idea ?


$ ionic info

Your system information:

Cordova CLI: 6.1.1
Gulp version:  CLI version 3.9.1
Gulp local:   Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.4
Ionic CLI Version: 2.0.0-beta.25
Ionic App Lib Version: 2.0.0-beta.15
ios-deploy version: 1.8.5
ios-sim version: 5.0.6
OS: Mac OS X El Capitan
Node Version: v5.7.0
Xcode version: Xcode 7.3 Build version 7D175

$ ionic platform list

Installed platforms:
android 5.1.1
ios 4.1.1

$ cat config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.ionicframework.gcloud334958" version="0.0.1" 
    <name>Moblie App</name>
    <description>Mobile App</description>
    <author email="" href="example.com">Mobile App</author>
    <content src="index.html" />
    <allow-navigation href="*" />
    <allow-intent href="*" />
    <access origin="*" />
    <platform name="android">
        <allow-intent href="market:*" />
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    <preference name="webviewbounce" value="false" />
    <preference name="UIWebViewBounce" value="false" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="android-minSdkVersion" value="22" />
    <preference name="android-targetSdkVersion" value="23" />
    <preference name="BackupWebStorage" value="none" />
    <feature name="StatusBar">
        <param name="ios-package" onload="true" value="CDVStatusBar" />
    <plugin name="cordova-plugin-device" spec="~1.1.1" />
    <plugin name="cordova-plugin-console" spec="~1.0.2" />
    <plugin name="cordova-plugin-whitelist" spec="~1.2.1" />
    <plugin name="cordova-plugin-statusbar" spec="~2.1.2" />
    <plugin name="ionic-plugin-keyboard" spec="~2.0.1" />

ADB log from time of starting app until error is thrown:

Nothing in this one as well :frowning: .

$ adb logcat | grep -i -E “gcloud|cordova”

I/Timeline( 1676): Timeline: Activity_launch_request id:com.ionicframework.gcloud334958 time:1618352521
I/ActivityManager(  873): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.ionicframework.gcloud334958/.MainActivity bnds=[540,828][792,1128]} from uid 10097 on display 0
V/WindowManager(  873): addAppToken: AppWindowToken{271ebc36 token=Token{196379d1 ActivityRecord{279290f8 u0 com.ionicframework.gcloud334958/.MainActivity t3824}}} to stack=1 task=3824 at 0
V/WindowManager(  873): Based on layer: Adding window Window{227a9209 u0 Starting com.ionicframework.gcloud334958} at 3 of 9
I/ActivityManager(  873): Start proc 26432:com.ionicframework.gcloud334958/u0a319 for activity com.ionicframework.gcloud334958/.MainActivity
D/SystemWebViewEngine(26432): CordovaWebView is running on device made by: Sony
V/WindowManager(  873): Adding window Window{3ce9eb58 u0 com.ionicframework.gcloud334958/com.ionicframework.gcloud334958.MainActivity} at 3 of 10 (before Window{227a9209 u0 Starting com.ionicframework.gcloud334958})
I/ActivityManager(  873): Displayed com.ionicframework.gcloud334958/.MainActivity: +547ms
I/Timeline(  873): Timeline: Activity_windows_visible id: ActivityRecord{279290f8 u0 com.ionicframework.gcloud334958/.MainActivity t3824} time:1618353104
V/WindowManager(  873): Adding window Window{3e1872a0 u0 PopupWindow:19f4c00a} at 4 of 10 (after Window{3ce9eb58 u0 com.ionicframework.gcloud334958/com.ionicframework.gcloud334958.MainActivity})
V/WindowManager(  873): not Base app: Adding window Window{305ae715 u0 com.ionicframework.gcloud334958/com.ionicframework.gcloud334958.MainActivity} at 6 of 11

I’ve only just quickly looked at this, but make sure your SSL certificate is configured correctly. Android is a little more iffy about it than iOS is, and sometimes even though https works in some browsers it may still be configured incorrectly.

There’s free tools you can run your website through online to check the certificate. Also double check the whitelist plugin and your Content Security Policy but it sounds like that is all good since iOS is working.

  1. Actually SSL isn’t issue - same getting against github public API:

jquery.min.js:4 GET https://api.github.com/users/vukasin0 net::ERR_CACHE_MISS

  1. Content Security Policy - is OK too, otherwise it will not work from browser.

Check into android manifest if there is INTERNET permission.

Holy crap - you made it.

Just checked and it was missing.
This perm should come with adding platform but not to add manually.

Just created new test project and it was there - now I understand why removing / re-adding platforms usually solves bunch of issues to developers.

Thanks a lot bro :smiley:

You welcome Bro :smile: :smile: :smile: