function onNetChange() {
var nt = plus.networkinfo.getCurrentType(); //
if (nt == "2" || nt == "3" || nt == "5" || nt == "6") {
mui.toast("");
var tx = db.transaction("users", READ_WRITE); //
var store = tx.objectStore("users"); //
var index = store.index("Ifnet"); //
var req = index.openCursor(IDBKeyRange.only("1")); //
req.onsuccess = function(evt) { //
var res = evt.target.result;
if (res) {
var net = [res.value]
for (j = 0; j < net.length; jPP) {
mui.ajax("http://XXXXX", {
data: {
tugwork_s_id: net[j].TUGWORK_S_ID,
IsMooring: net[j].If_mooring,
IsPickup: net[j].ISPICKUP,
godate: net[j].Godate,
startdate: net[j].Startdate,
enddate: net[j].Enddate,
backdate: net[j].Backdate
},
dataType: "json",
type: "post",
timeout: 5000,
success: function(res) {
console.log(JSON.stringify(res));
},
error: function(xhr, type, errorThrown) {
console.log("Update_local");
}
});
}
res.continue(); //
}
};
req.onerror = function(evt) { //
console.error("UpData error:", evt.target.errorCode || evt.target.error);
};
}
else {
mui.toast("");
}
}
This is what the code looks like, and it"s very confusing for me to write and send AJAX. Although the data was saved successfully. I want to write a recursive method but I don"t know how to write it. Ask some great god to help me see how I can make this for loop recursive. For example, I found three pieces of data that meet the criteria locally. Then I send three AJAX requests. Failure is not considered for the time being. By default, it is all successful ideally.