过去几年,我一直在使用适用于iOS和Android的cordova应用程序中成功使用以下同步库 https://github.com/abeauseigle/TodoApp
突然间,似乎与iOS> 10.3更新有关,我开始遇到问题: 一切都运作良好 - 涟漪 - Android模拟器 - iOS模拟器
在带有iOS 10.3.1的真实设备 iPhone 5上,不执行websql部分。
我倾向于认为整个ajax调用不会发生在一起。
这里是电话:
_sendDataToServer: function(dataToSync, uploadProgressCallBack, downloadProgressCallBack, finishCallBack) {
var self = this;
var XHR = new window.XMLHttpRequest(),
data = JSON.stringify(dataToSync);
console.log("Line 261 clientData:",data);
XHR.overrideMimeType = 'application/json; charset=UTF-8';
XHR.open("POST", self.serverUrl, true);
//XHR.timeout = 300000; //default: no timeout
XHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
XHR.onreadystatechange = function() {
var serverAnswer="";
if(4 === XHR.readyState) {
try{
serverAnswer = JSON.parse(XHR.responseText);
console.log("Line 293 Server answered:",serverAnswer);
} catch(e) {
serverAnswer = XHR.responseText;
console.log('e.message: ',e.message);
console.log("Line 297 Server answered:",serverAnswer);
}
self.log('Line 300 Server answered: ');
self.log(serverAnswer);
//I want only json/object as response
if(XHR.status == 200 && serverAnswer instanceof Object) {
console.log("websqlsync ok");
finishCallBack(serverAnswer);
} else {
serverAnswer = {
result : 'ERROR',
status : XHR.status,
message : XHR.statusText
};
console.log("websqlsync PROBLEM");
finishCallBack(serverAnswer);
}
}
};
XHR.send(data);
}
在所有控制台日志中,我只看到第一个:
Line 261 clientData:
问题仅发生在REAL DEVICE上...... 有什么建议吗?
由于
答案 0 :(得分:0)
经过几个小时和错误的尝试后,我发现设置超时解决了问题:
XHR.timeout = 300000;
我希望这可以帮助别人(当然会提醒我)。