问题
I recently updated my Xcode to 12.0, and I have the latest iOS 14, and Cordova 10.0.0 on my mac. I also changed the UIWebview
to WKWebViewOnly
I have also referred to the following link to enable the option in the config file:
Ajax Not working in IOS 9.0 Cordova
So, my config file looks something like this
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<preference name="AllowUntrustedCerts" value="on" />
<preference name="InterceptRemoteRequests" value="all" />
<preference name="NativeXHRLogging" value="full" />
<preference name="WKWebViewOnly" value="true" />
<feature name="CDVWKWebViewEngine">
<param name="ios-package" value="CDVWKWebViewEngine" />
</feature>
<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
</platform>
My code works fine in Android, but the following code which I call on the click of a button (after the device ready event has been called) fails:
var postData = "&UserName=" + user1;
$.ajax({type: 'POST',
data: postData, url: "http://webaddress.com",
timeout:120000,
complete: function(jqXHR, textStatus) {alert("done");},
success: function(dataMain){
},
error: function(xhr, ajaxOptions, thrownError){
//console.log(data);
alert("error " + ajaxOptions + " " + thrownError);
// if (ajaxOptions === "timeout") { openAlertMsg(timeoutMsg); }
hideLoading();
}
});
I also tried to add the following to the index.html
<meta http-equiv="Content-Security-Policy" content="connect-src *; style-src 'self' 'unsafe-inline'; media-src *">
I assume Cordova runs fine with Ajax, in fact, in my older version of Cordova and Xcode, it was running fine, but am facing this issue very recently.
回答1:
please add crossDomain : true to your ajax args
来源:https://stackoverflow.com/questions/64064651/cordova-10-0-ajax-not-working-in-ios-14-but-working-fine-in-android