在单击提交按钮时,我想在用户在线时发出发帖请求。如果用户离线,我想将提交的数据存储在本地存储中。不幸的是,关闭wifi后单击“提交”按钮时出现500错误。当我从浏览器网络脱机时,它会起作用
onSubmit() {
let postData = [];
for (var groupId in this.deltasByGroupId) {
if (!this.deltasByGroupId.hasOwnProperty(groupId)) { continue }
for (var k in this.deltasByGroupId[groupId]) {
if (!this.deltasByGroupId[groupId].hasOwnProperty(k)) { continue }
let secs = this.deltasByGroupId[groupId][k];
var item1 = secs["items"]
for (var j in item1) {
var item2 = item1[j]
for (var l in item2) {
var listItem = item2["items"]
for (var li in listItem) {
this.model = new MeasurementChange(listItem[li].id, listItem[li].percent_complete);
postData.push(this.model);
}
}
}
}
}
if(navigator.onLine){
this.pEntryService.postEntries(postData).subscribe(res => {
alert("Data submitted successfully")
})
} else{
this.storage.set('cashedData', postData).then(res => {
alert("Data successsfully stored locally")
})
}
}