我们可以在IndexedDB中的另一个事务中创建一个事务吗?我想将我的indexedDB数据导出到我的Server。为此,我使用游标进行迭代,并在成功插入后将数据发送到我的Server,我希望删除IDB中的相同数据。在这样做时,我得到了TransactionInactive错误:您的事务不是活动的。给出了一些解决这个问题的建议。
var trans = db.transaction(["Applicant"],"readwrite");
var store = trans.objectStore("Applicant");
//console.log(store);
var index = store.index("AM_Applicant_Name");
var key = IDBKeyRange.lowerBound(0);
var cursor = index.openCursor(key);
//console.log(cursor);
cursor.onsuccess = function(e) {
var result = e.target.result;
console.log(result);
if(result) {
alert(result.value["AM_Applicant_Name"]+" "+result.value["AM_Father_Name"] +" "+result.value["id"]);
// Code To Save IDB values to Sql Server
if (window.XMLHttpRequest) {
var sPath = "IndexedDB.aspx?Insert=Y";
console.log(sPath);
var xhr = new XMLHttpRequest();
xhr.open("POST", sPath, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
if (xhr.responseText != "") {
}
alert(xhr.getResponseHeader("Y-Result")+" and "+xhr.getResponseHeader("Y-Id"));
if (xhr.getResponseHeader("Y-Result") == "Y") { //Check Data Insertion is Success or Not
alert("Moved Successfully.");
}
if (xhr.getResponseHeader("Y-Id") != "") { //Check Data Insertion is Success
alert(xhr.getResponseHeader("Y-Id")+"ds");
//Delete From IDB
store.delete(xhr.getResponseHeader("Y-Id")); **Here I am getting the error**
console.log("Record Deleted From IndexedDB");
}
}
}
//Passing Parameters to Server Side Events
xhr.setRequestHeader("District_Code", result.value["AM_District_Code"]);
xhr.setRequestHeader("Taluk_Code", result.value["AM_Taluk_Code"]);
xhr.setRequestHeader("Hobli_Code", result.value["AM_Hobli_Code"]);
xhr.setRequestHeader("Village_Code", result.value["AM_Village_Code"]);
xhr.setRequestHeader("Habitation_Code", result.value["AM_Habitation_Code"]);
xhr.setRequestHeader("Reservation_Code", result.value["AM_Reservation_Code"]);
xhr.setRequestHeader("Caste_Code", result.value["AM_Caste_Code"]);
xhr.setRequestHeader("Applicant_Name", result.value["AM_Applicant_Name"]);
xhr.setRequestHeader("Father_Name", result.value["AM_Father_Name"]);
xhr.setRequestHeader("Mobile_No", result.value["AM_Mobile_No"]);
xhr.setRequestHeader("Address", result.value["AM_Address"]);
xhr.setRequestHeader("Address1", result.value["AM_Address1"]);
xhr.setRequestHeader("Address2", result.value["AM_Address2"]);
xhr.setRequestHeader("Pin_Code", result.value["AM_Pin_Code"]);
xhr.setRequestHeader("Id", result.value["id"]);
xhr.send();
}
result.continue();
}
}发布于 2014-03-24 11:37:42
谢谢你的提问。
您可以获得TransactionInactiveError,因为要预编格式的delete操作发生在ajax调用的回调中。
indexeddb是自动提交,这意味着一旦完成了事务上的操作,事务就提交了。在您的情况下,一旦游标中的所有结果被迭代,事务将被执行。事务不会等待可能的额外调用,因为异步回调是可以执行的。
因此,您应该立即删除该项,或者为每次删除打开一个新事务。
https://stackoverflow.com/questions/22605065
复制相似问题