Ios – Ajax call fails with HTTP status 0 when using Cordova WKWebView plugin on iOS

ajaxcordovaiosuiwebviewwkwebview

I've been trying to update my Cordova iOS app to use the new WKWebView pluggable web view, but I have run into an issue where I cannot make ajax calls when it is installed. When I try to make the following call, I get a an error result of HTTP status 0:

return Promise.resolve($.ajax({
        url: 'https://mytestserver.com/settings',
        timeout: 10000 
    }))

I am using Cordova 5.4.1 with iOS platform 4.0.0 and my test device is running iOS 9.2. This code works as expected as soon as I remove the WKWebView plugin and Cordova reverts to UIWebView. I have tried with and without the whitelist plugin (1.2.0).

My config.xml includes:

<access origin="*" />

My index.html CSP tag is:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: cdvfile: https://ssl.gstatic.com 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *; img-src *; connect-src https: blob: 'self'; object-src 'self' blob:;">

Best Answer

Have you read the Limitations section of the doc?

If you are upgrading from UIWebView, please note the limitations of using WKWebView as outlined in our issue tracker.

I think your problem is that WKWebView is affected by CORS

So you have to set Access-Control-Allow-Origin: * on the server

Examples

Related Topic