0

I'm trying to do an ajax call as following:

(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.
};
} )();

meta tag:

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

The errors Visual studio is giving me is as followning:

Unrecognized Content-Security-Policy directive 'script-src:'.
index.html (4,0)

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
jquery-1.11.3.js (9626,29)

Failed to load resource
jquery-1.11.3.js (9665,29)

It worked for me 20 minutes ago but before that i had a different problem that i solved Old Qestion and now I'm sitting here with this problem instead.

Somethings that i have tried

  1. Building it via AdobePhoneGap builder instated of building it via visual studio

  2. try it on emulator (This works for some reason)

Additional info and ides after some testing

The problem only seems to happen on android devices and not on emulators can there be something wrong with my android phone?

Community
  • 1
  • 1
Kladfizk
  • 99
  • 1
  • 17

1 Answers1

0

Seams like all i had to do was to change the meta tag to this

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

Then again how unsafe is this to have on an phone app? On a webpage i can see the concerns, but on an ios/windows8/android app will the possibilitys be the same for someone to do something mischievous

I'll guess ill have to rework the meta tag in the future just to be safe :) If you have any good reading i would like if you could share some of it with me so it might help someone in the future!

Let's hope i don't jinx this again whit saying it works.

Kladfizk
  • 99
  • 1
  • 17