Get data from OData with datajs and save to sqlite in phonegap

I am developing an app in phonegap which get data from OData with datajs and save it to sqlite. datajs works fine, but when I try to save data to sqlite I get the error " E/Web Console(11533): Uncaught Error: INVALID_STATE_ERR: DOM Exception 11 at file:///android_asset/www/js/core/Sincronizacion.js:19"

This is the code:

function SincronizarClientes()  // This function runs after a button click
    var db = window.openDatabase("TestDb", "1.0", "TestDb - 1", 2000000);
    db.transaction(ActualizarClientes, FalloSincronizacion, OkSincronizacion);  

function ActualizarClientes(tx)
{"$filter=EQUIPO eq 'T1' and startswith(NOM_UCLIENTE, 'MIGUEL') eq true",
    function (data, request) {
        var html = "", sql = "";
        for (var i = 0; i < data.results.length; i++) {
            html += "<div>" + data.results[i].NOM_UCLIENTE + "</div>";
            sql = "INSERT OR REPLACE INTO Clientes (Cod_UCliente, Nom_UCliente, Fecha_Actualizacion) VALUES ('" + data.results[i].COD_UCLIENTE + 
                          "','" + data.results[i].NOM_UCLIENTE + "', datetime())";
            //sql = "INSERT OR REPLACE INTO Clientes (Cod_UCliente, Nom_UCliente, Fecha_Actualizacion) VALUES ('00012125', 'PEDRO PEREZ PINTO', datetime())";              
            tx.executeSql(sql);  //This is line 19
        document.getElementById("mainContent").innerHTML = sql;

        alert("Los clientes se actualizaron correctamente!");
    },  function(err) {
            alert("Error occurred " + err.message);

// Transaction error callback
function FalloSincronizacion(tx, err) {
    alert("Error actualizando los clientes: " + err);

// Transaction success callback
function OkSincronizacion() {



INVALID_STATE_ERR is not an SQLite error.

I'd guess that your OData callback function is run asynchronously, after SincronizarClientes() has returned, so the transaction tx is already closed.

Call db.transaction() inside the callback function instead.

Need Your Help

Tap Gesture to Hide Navigation Bar, Tab Bar, and Status Bar

ios uigesturerecognizer show-hide

I am trying to implement a tap gesture on my web view to hide/show the navigation bar, tab bar, and status bar. I have the hiding/showing of the navigation bar working fine and I can hide the stat...

STM32439I-EVAL2 board problems with camera

camera embedded stm32

I am working with the STM32439I-EVAL2 board and my OV2640 camera is not functioning properly. I have been testing it with the MB1063 Demonstration example from the STM32CubeF4 software and when I t...