Can't do ajax calls from android device because cordova-plugin-whitelist is not installed but i can't install it?

蹲街弑〆低调 提交于 2019-12-12 06:21:35

问题


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!


回答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!



来源:https://stackoverflow.com/questions/31874795/cant-do-ajax-calls-from-android-device-because-cordova-plugin-whitelist-is-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!