racekarl
racekarl

Reputation: 91

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

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:;">

Upvotes: 3

Views: 5856

Answers (2)

Mr_Marte
Mr_Marte

Reputation: 1

In index.html the ajax work correctly but in anothers html files didn't, so i had to use index like master page for another files modifying the app and the app work.

Upvotes: 0

jcesarmobile
jcesarmobile

Reputation: 53301

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

Upvotes: 6

Related Questions