I have a Cordova app built on Cordova 11.0
It uses the following platform versions
- android 10.1.2
- browser 6.0.0
- ios 6.3.0
It users the following plugins
- cordova-plugin-android-permissions 1.1.5 "Permissions"
- cordova-plugin-device 2.1.0 "Device"
- cordova-plugin-file 7.0.0 "File"
- cordova-plugin-geolocation 4.1.0 "Geolocation"
- cordova-plugin-statusbar 3.0.0 "StatusBar"
- cordova-plugin-wkwebview-file-xhr 3.1.0 "Cordova WKWebView File XHR Plugin"
config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="id" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>name</name>
<description>desc</description>
<author email="my@email.com">
whiz bang development
</author>
<icon src="res/icon.png" />
<preference name="AndroidInsecureFileModeEnabled" value="true" />
<content src="index.html" />
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
</edit-config>
</platform>
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="*" />
</widget>
I was under the impression the above would eliminate CORS as a problem.
However, when I run in the browser, the console shows me the errors
jquery-1.11.1.js:9624 Refused to set unsafe header "Origin"
Access to XMLHttpRequest at 'http://11.111.111.111:8081/service' from origin 'http://localhost:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
POST http://11.111.111.111:8081/service net::ERR_FAILED
The failing bit of code is
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
timeout: 30000,
crossDomain: true,
headers: { 'Access-Control-Request-Methods': 'POST',
'Access-Control-Allow-Origin': '*',
'Origin': 'http://localhost:8000'},
url: options.server + "/service",
data: JSON.stringify(param),
success: function (msg) {
//rejoice
},
error: function (x, t, m) {
console.log("error getting results x=" + JSON.stringify(x) + " t=" + t + " m=" + m);
}
});
The error produced is
"error getting results x={"readyState":0,"responseText":"","status":0,"statusText":"error"} t=error m="
When I open the browser as follows
open /Applications/Google\ Chrome.app --args --user-data-dir="/var/tmp/chrome-dev-disabled-security" --disable-web-security --disable-site-isolation-trials
I do NOT get any of the errors.
When I run on Android I get the error message:
"error getting results x={"readyState":0,"responseText":"","status":0,"statusText":"error"} t=error m="
I had thought changing stuff so it would run in the browser would fix the problems in Android but I was wrong.
How do I make this work in Android?