We are currently engaged in a project hosted by our university.
We are supposed to open a JSON file with some data in it, provided by a web server.
The code that is used in this scenario is the following:
listeAbrufen: function() {
var load = new XMLHttpRequest();
load.open("POST", Artikel.linkToServer, true); //Link to server
load.setRequestHeader("Content-Type","application/json;charset=UTF-8");
var json = {'requestType':'GETDB','DBPATH':'/db/artikel/getList'};
load.send(JSON.stringify(json));
load.onreadystatechange = function() {
/* Request bearbeitet */
if (load.readyState == 4 && load.status == 200) {
var response = JSON.parse(load.responseText);
console.log("listeAbrufen response:"+JSON.stringify(load.responseText));
if (response['response'] == "OK" ) {
Artikel.liste = response['list'];
console.log("listeABrufen Artikelliste: " + JSON.stringify(Artikel.liste));
Artikel.listeAnzeigen("speisekarte__artikel", false);
Error.hide();
} else {
Error.show(response['errorcode'],response['message']);
}
} else if (load.readyState >= 4) {
Error.show("keineVerbindung");
}
}
},
This code is working fine in every browser (latest versions of Chrome, Firefox, Opera), the response is coming in and is working. However, in Safari the console is giving an error:
Failed to load resource: Die Netzwerkverbindung wurde unterbrochen.
(Failed to load resource: The network connection was lost.)
In the Debugger, we figured out that the load.status variable contains zero, while its checked for 200 in the if-branch.
This again only occurs in Safari on iOS devices and Macbooks, the code is working with the browsers listed above.
In the logs from the server, we saw that the request reaches the server and a correct response is generated, just like with other browsers, but the status code stays 0 in Safari, the connection gets closed and no further communication happens. This was also tested on multiple devices, all with the latest Safari/iOS/OSX Versions.