在phonegap中更新数据库

I'm getting the following error:

Uncaught Error: INVALID_STATE_ERR: DOM Exception 11

I get this error message when trying to execute a query.

Did anyone ever get the same problem ?

function populateDB(tx) {

    tx.executeSql('DROP TABLE IF EXISTS ORDERS');
    tx.executeSql('CREATE TABLE IF NOT EXISTS ORDERS (id INTEGER PRIMARY KEY, client_ID, status)');

    var myurl="xml.xml";
    $.ajax({
        type: "POST", 
        url: myurl, 
        dataType: "xml", 
        success: onSuccess
    }); 
}

function onSuccess(xml) {

    $(xml).find('articles').each(function () {
        var idord = $(this).attr('id');

        var esql ='INSERT INTO ORDERS (id, client_ID, status) VALUES ('+idord+', 4, "done" )';
        var nameclient = $(this).find('name').text();
        $('.items').append('<h2>'+ nameclient '</h2>').appendTo('#xml-data'); 

        tx.executeSql(esql) ;
    });  
}

Try defining your function onSuccess inside your function populateDB as follows:

function populateDB(tx) {

    tx.executeSql('DROP TABLE IF EXISTS ORDERS');
    tx.executeSql('CREATE TABLE IF NOT EXISTS ORDERS (id INTEGER PRIMARY KEY, client_ID, status)');

    var myurl="xml.xml";
    $.ajax({
        type: "POST", 
        url: myurl, 
        dataType: "xml", 
        success: function(xml) {

            $(xml).find('articles').each(function () {
                var idord = $(this).attr('id');

                var esql ='INSERT INTO ORDERS (id, client_ID, status) VALUES ('+idord+', 4, "done" )';
                var nameclient = $(this).find('name').text();
                $('.items').append('<h2>'+ nameclient '</h2>').appendTo('#xml-data'); 

                tx.executeSql(esql) ;
            });  
        }

    }); 
}

Let me know if this works mate.