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!
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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.