I want to run a transaction inside a for loop. My code is :-
for(var i=0;i<len;i++){
// some code
alert('before transaction');
var db = window.openDatabase("Database", "1.0", "Pin Point", 200000);
db.transaction(fetchSubList, errorLists);
alert('after transaction');
}
function fetchSubList(tx) {
tx.executeSql('some QUERY', [], fetchSubListSuccess, errorLists);
}
function fetchSubListSuccess(tx, results) {
alert("fetchSubListSuccess()...");
// some code
}
But the problem is that after the alert (before transaction) i directly get alert (after transaction) and only when the for loop ends then the transaction start….
I followed the this link to solve but still i’m not able to figure it out….
It is not possible to do it… We need to refactor the code so that code looks like this :-