Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SQLite成功回调在事务完成之前激发_Javascript_Asp.net_Sqlite_Web Sql - Fatal编程技术网

Javascript SQLite成功回调在事务完成之前激发

Javascript SQLite成功回调在事务完成之前激发,javascript,asp.net,sqlite,web-sql,Javascript,Asp.net,Sqlite,Web Sql,在我的ASP.NET web表单应用程序中,我需要执行一些JQuery操作来收集表单数据,然后迭代表单数据以保存到SQLite数据库,并在成功完成后关闭当前窗口。如果窗口保持打开状态,则保存操作可以正常工作,但只要我添加窗口。在SQLite事务中成功回调之前,窗口似乎在保存操作完成之前关闭 function save(closeWindow) { //Gathering form data and creating the checkListInsert string containing

在我的ASP.NET web表单应用程序中,我需要执行一些JQuery操作来收集表单数据,然后迭代表单数据以保存到SQLite数据库,并在成功完成后关闭当前窗口。如果窗口保持打开状态,则保存操作可以正常工作,但只要我添加窗口。在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秒钟,一切正常。因此,这绝对是一个时间问题。似乎在事务完成之前不应该启动回调

使用表单中的行数作为预期插入的行数。比较一下 到受结果影响的
行,以验证事务是否完成:

if (closeWindow == "Yes") 
  {
  if (result.rowsAffected === /*Number of rows inserted*/)
    {
    window.close();
    }
  }

您应该等待事务完成,而不是executeSql:

function save(closeWindow) {
    db.transaction(function (tx) {
        tx.executeSql(checkListInsert.substring(0, checkListInsert.length - 6), []);
    }, function () { }, function () {
        if (closeWindow == "Yes") {
            window.close();
        }
    });
}

我们需要查看executeSql内部的代码。我假设这就是Ajax隐藏的地方,乍一看,它似乎没有正确地以回调的形式运行close函数,我不确定您在寻找什么代码。executeSql在那里。对executeSql的调用在那里。函数中的代码不存在。所有代码都存在。checkListInsert是我的SQL insert语句,后面是[],因为没有参数,后面是包括if语句的成功回调,后面是onSQLError回调。是的,函数调用和参数列表在那里。我们需要看看在executeSql内部发生了什么。或者至少我感觉executeSql是某种第三方库的一部分。它是?如果是,是什么?