【发布时间】:2016-01-30 06:23:16
【问题描述】:
在我的 ASP.NET Web 表单应用程序中,我需要执行一些 JQuery 操作来收集表单数据,然后遍历表单数据以保存到 SQLite 数据库,并在成功完成后关闭当前窗口。如果窗口保持打开状态,保存操作可以完美运行,但是一旦我将 window.close 添加到我的 SQLite 事务中的成功回调,窗口似乎在保存操作有时间完成之前关闭。
function save(closeWindow)
{
//Gathering form data and creating the checkListInsert string containing my bulk insert statement (i.e. Insert Into Table Select .... Union Select...)
db.transaction(function (tx) {
tx.executeSql(checkListInsert.substring(0, checkListInsert.length - 6), [], function (tx, result) {
if (closeWindow == "Yes") {
//window.close(); If left uncommented the data will not save. When left commented the save occurs but of course the window is still open
}
}, onSQLError);
});
}
编辑:如果我将 window.close() 放在 window.setTimeout() 内 1 秒,一切正常。所以这绝对是一个时间问题。似乎在事务完成之前回调不应该触发?!
【问题讨论】:
-
我们需要看看executeSql里面的代码。我会假设这是 Ajax 隐藏的地方,乍一看,它似乎没有正确地将您的关闭函数作为回调运行。
-
我不确定您要查找的代码。 executeSql 就在那里。
-
其中有一个对 executeSql 的调用。函数里面的代码不是。
-
所有代码都在那里。 checkListInsert 是我的 SQL 插入语句,后跟 [] 因为没有参数,然后是我的成功回调,其中包括 if 语句,然后是我的 onSQLError 回调。
-
是的,函数调用和参数列表都在那里。我们需要看看executeSql的inside之后会发生什么。或者至少我觉得 executeSql 是某种 3rd 方库的一部分。是吗?如果有,是什么?
标签: javascript asp.net sqlite web-sql