0

I'm having this rather weird problem i built an app for android using cordova and had ajax call in it and they worked but for some reason after i got a BSoD on my PC all the ajax calls stopped working when i published the app again to my android phone.

My first thought was that Visual Studio did not add the cordova-plugin-whitelist so i did a new project and tried to add the plugin to test if this was the problem, but now when i add the plugin my build fails and the output window shows this Output on pastebin(will expire on 2015-09-07)

The ajax call works on Android emulator and Ripple if cordova-plugin-whitelist is not installed

Javascript:

(function () {
"use strict";

document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false );

function onDeviceReady() {
    // Handle the Cordova pause and resume events
    document.addEventListener( 'pause', onPause.bind( this ), false );
    document.addEventListener( 'resume', onResume.bind( this ), false );
    $.ajax({
        url: 'https://www.path.com/Controller/Action',
        async: false,
        type: "GET",
        dataType: "json",
        beforeSend: function () { $.mobile.loading('show'); },
        success: function (DataToFillSelect) {
            $.each(DataToFillSelect, function (val, item) {
                $('#Select').append(
                    $('<option></option>').val(item.Value).html(item.Text)
                );
            });
        },
        error: function () {

        },
        complete: function () { $.mobile.loading('hide'); },
    })
    // TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.
};

function onPause() {
    // TODO: This application has been suspended. Save application state here.
};

function onResume() {
    // TODO: This application has been reactivated. Restore application state here.
};
} )();

It's just the blank template with an added ajax call onDeviceReady function

If you need anything more from me just ask i'll be here all day :) Thanks for taking your time to help me solve this issue of mine!

Kladfizk
  • 89
  • 1
  • 15
  • 1
    try run your app with console. `cordova run android` – Randyka Yudhistira Aug 07 '15 at 09:59
  • app builds and get's published to phone but ajax call is not working – Kladfizk Aug 07 '15 at 10:08
  • I tryed to add cordova-plugin-whitelist with cmd instated of using Visual studio and git. and it's added but there is no entry in the config.xml file? there should be one right? – Kladfizk Aug 07 '15 at 11:17
  • now i can add the plugin with Visual studio and git and it's added in the config.xml as it should and this is so weird why it works now all of a sudden? But this of course gave me a new error and is probably the reason why it didn't work in the first place `No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.` – Kladfizk Aug 07 '15 at 13:09
  • 1
    In that case, your question is probably a duplicate of [“No Content-Security-Policy meta tag found.” error in my phonegap application](http://stackoverflow.com/questions/30212306/no-content-security-policy-meta-tag-found-error-in-my-phonegap-application) – Huey Aug 07 '15 at 15:27
  • What should you add for ajax calls? – Kladfizk Aug 10 '15 at 08:29
  • I'm really confused i removed the cordova-plugin-whitelist and added a Content-Security-Policy meta tag and now it works code is still the same can someone tell why this works?! sure I'm happy it works but why? – Kladfizk Aug 10 '15 at 08:36

1 Answers1

1

Removed the cordova-plugin-whitelist from config.xml and from the project and added meta tag containing

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src: 'self' 'unsafe-inline' 'unsafe-eval'">

And now it works again i don't know why If anyone can explain it to me i would be happy, sure I'm still happy it works but you know knowing why it works would be preferable :)

Thx for all the help!

Kladfizk
  • 89
  • 1
  • 15