2

I generate an app with Cordova and XCode. The app contains local (!) Ajax-Requests to JSON-files which work fine in the last version of the app also in iOS. Now, without having changed anything about the code, it does in iOS no longer work. In a common browser (incl. Safari) and in Android via Android Studio it works fine.

The code is simple as this:

$.getJSON('test_json_data.json', function(data) {
    alert data['something'];
})

The JSON-File is:

{"something":188}

So there is no Cross-Origin-Scripting or anything. It is just a local call. To get more information about the problem I changed it to the following. This also works fine in common browser and in Android, but not in iOS. In iOS it only gives me back an "error" but not what the error is about.

$.ajax({
    type: "GET", 
    dataType: 'json', 
    url: 'test_json_data.json',
    async: false,
    contentType: "application/json; charset=utf-8",
    success: function (data) {
        alert data['something'];
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        alert("some error: " + textStatus + "/" + errorThrown);
    }
});

I tried adding a Content-Security-Policy

<meta http-equiv="Content-Security-Policy" content="default-src * 'self' data: 'unsafe-inline' 'unsafe-eval'">

but this also didn't help. In plist-file of the cordova app Allow Arbitrary Loads is set to true.

I (guess I) also changed from UIWebView to WKWebView by recreating the app with cordova and using

cordova platform add ios@6.2.0

instead of

cordova platform add ios

Now I have no more ideas what to try. Does someone have an idea?

Tom
  • 281
  • 4
  • 7

1 Answers1

2

After hours of research I found out that after adding ios@6.2.0 I also have to perform

cordova plugin add https://github.com/AraHovakimyan/cordova-plugin-wkwebviewxhrfix

to fix the wkwebviewxhr-Problem. See here: AraHovakimyan / cordova-plugin-wkwebviewxhrfix

Tom
  • 281
  • 4
  • 7
  • Very helpful, thanks so much for coming back to your question. I actually used which uses the plugin you linked, as I do not think it is supported anymore. – Michael Jul 05 '21 at 17:45
  • Thank you for answer, you really helped me a lot, I have tried to bug fix this on my own locally, but without success. – Max Nov 12 '21 at 12:40