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?