Icenium 1.10 cordova 3.2 and ajax post

6 posts, 0 answers
  1. Marco
    Marco avatar
    7 posts
    Member since:
    Nov 2013

    Posted 12 Dec 2013 Link to this post

    Dear Telerik 
    I updated my Icenium project from cordova 3.0 to 3.2.
    In my code I have and ajax post to our company server and with cordova 3.2 does not work ( status error 0). If I go back to cordova 3.0 the same code works perfectly.
    Can you please help me? It could be a wrong conversion of the internet permission?

    Marco
  2. Pier Alberto
    Pier Alberto avatar
    16 posts
    Member since:
    Jun 2013

    Posted 13 Dec 2013 Link to this post

    I've exactly the same problem. On iOS the app works perfectly (also with the new StatusBar plugin which solved a big problem). Unfortunately when ran on Android, every Ajax call fails with Status=0.
    In my mobileinit event I've set 

    $.mobile.allowCrossDomainPages = true;
    $.support.cors = true; 

    I suspect there is something between Cordova 3.2.0 and jQuery.
    Any help is appreciated.

    Pier Alberto
  3. Pier Alberto
    Pier Alberto avatar
    16 posts
    Member since:
    Jun 2013

    Posted 13 Dec 2013 Link to this post

    I tried to go deeper into this issue.
    I tested the sample-translator app, which uses cordova 3.2. The same ajax call failing in my app, in the sample app works perfectly. Same permissions, same config.xml and same android.manifest as my app.
    The only difference is that my app uses jquery mobile 1.3.2, while the sample app uses 1.3.1. I suppose this can't be the reason of the issue because $.ajax is define in the jquery library (1.9.1 for both apps).

    Pier Alberto Guidotti
  4. Pier Alberto
    Pier Alberto avatar
    16 posts
    Member since:
    Jun 2013

    Posted 13 Dec 2013 Link to this post

    I finally solved the problem. I had to change the Android config.xml by replacing:

    <access origin=".*"/>

    (which I suppose to be the default setting) with:

    <access origin="*"/>

    It does make sense, I don't understand why it was working well with the previous setting.
  5. Marco
    Marco avatar
    7 posts
    Member since:
    Nov 2013

    Posted 14 Dec 2013 Link to this post

    Thanks Pier Alberto, your solution works also for me. 
    Now ajax post works with cordova 3.2 and icenium
  6. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 14 Dec 2013 Link to this post

    Hi guys,

    It appears Pier is absolutely correct and the culprit is in a change Cordova did in v.3.1, namely Unify Whitelist Implemenations. If you create a brand new Icenium app and do not modify the config.xml, the .apk would be build with the new Cordova implementation, but if you edit the config.xml, we would add an outdated configuration file that still uses the old convention.

    In short as Pier listed, for existing apps that have their config.xml file edited, make sure that the following line is changed:
    from: <access origin=".*"/>

    to: <access origin="*"/>

    We would make the necessary changes on our end, so this problem does not surface in subsequent versions.

    Sorry for omitting this Cordova change guys (which btw is not listed as breaking)!

    Regards,
    Steve
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
Back to Top