0

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.

Harry J
  • 1,842
  • 3
  • 12
  • 28
Sam
  • 1
  • 1
  • Hi Sam, have You found a solution? I haven't tried my Cordova app on ios14 yet, but this problem terrifies me. – tartarismo Sep 28 '20 at 07:30
  • No luck yet, waiting for a solution asap. – Sam Sep 28 '20 at 10:57
  • 1
    Hi! It is very possible that something related with CORS is happening there, as WKWebView enforces that every petition pass cross origin validation. If you are accessing some remote url which you don't have permission to (CORS policy blocks your request), that error will happen. If it is your problem (you could check it on iOS Simulator, opening safari and checking developer console); you should request to enable CORS on that domain, or use some native plugin for requests ( as https://github.com/silkimen/cordova-plugin-advanced-http ) – Juan Miguel S. Sep 29 '20 at 15:50

1 Answers1

0

please add crossDomain : true to your ajax args

shyam.y
  • 1,441
  • 1
  • 16
  • 17