Ciao, mi accodo alla segnalazione di techno perchè anche io ho il medesimo problema, riporto a seguire un po' di dettagli.
In un'applicazione sviluppata in Cordova, che dovrebbe essere installata su palmare con s.o. Android Oreo, devo effettuare una chiamata ad un db MySQL, cosa che ho fatto sfruttando $ajax.
Il file config.xml è così strutturato:
codice:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.abc.xyz" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>AppName</name>
<description>AppDescription</description>
<author email="email@domain.it" href="https://www.domain.it">
Author
</author>
<content src="index.html" />
<access origin="http://192.168.2.100"/>
<access origin="https://192.168.2.100"/>
<allow-intent href="https://192.168.2.100/*" />
<allow-navigation href="https://192.168.2.100/*" />
<allow-intent href="http://192.168.2.100/*" />
<allow-navigation href="http://192.168.2.100/*" />
<preference name="android-minSdkVersion" value="27" />
</widget>
Mentre il tag meta CSP in index.html è dichiarato così:
codice:
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; connect-src 'self' http://192.168.2.100 https://192.168.2.100; media-src 'self'; img-src 'self';">
Questa invece la chiamata $ajax:
codice:
$.ajax({
url: link + "calltodb.php",
type: 'POST',
data: {"theQuery": id},
cache: false,
async: false,
dataType: "text",
crossDomain: true,
/*beforeSend: function(xhr) {
xhr.setRequestHeader("Access-Control-Allow-Origin", "http://localhost:8000");
//xhr.setRequestHeader("Access-Control-Allow-Origin", link + "calltodb.php");
return true;
},*/
success: function(data){
alert("success: " + data);
if (data != "" && data != "[]" && data != undefined && data != null){
aModelli = JSON.parse(data);
InitFromDB = true;
document.getElementById('ConsoleLog').innerHTML += "<br />aModelli: " + JSON.stringify(aModelli);
}
else{
InitFromDB = false;
nTentativi++;
}
},
error: function (xhr, status, error) {
alert("xhr.status: " + xhr.status + "; status: " + status + "; error:" + error);
InitFromDB = false;
}
});
Nella pagina php che risiede lato server ho indicato:
Codice PHP:
header("Access-Control-Allow-Origin:http://localhost:8000");
Da browser, con pc connesso alla rete, fila tutto liscio ed ottengo il JSON atteso.
Da dispositivo Android, connesso alla rete, ottengo lo stesso errore segnalato da techno.
Sapete indicarmi dove sta l'anomalia ?
Grazie in anticipo!
Maurizio