lundi 2 mai 2016

Save values in Database with javascript

I have a list of markers ( all draggable) that I load with xml file (generated from a local database with php). It is very easy to move the markers, but now I have a little problem to save the new positions in DB(sqlite). I would like to do an update on the database via javascript, but I didn't understand how to do this. I've tried this:

function Save()
{

     var db = openDatabase('/var/www/laravel/database/mydb.db', '1.0', 'mydb', 2 * 1024 * 1024);
     for(var i=0;i<marker_list.length;i++)
     {
         var pos= marker_list[i].getPosition();
         var title = marker_list[i].getTitle();
         db.transaction(function (tx) {
            tx.executeSql('update marker set position="'+pos+'" where title="'+title+'"');
         });
     }
}

and this:

function Save()
{

    var db = openDatabase('mydb', '1.0', 'mydb', 2 * 1024 * 1024);
    for(var i=0;i<marker_list.length;i++)
    {
        var pos= marker_list[i].getPosition();
        var title = marker_list[i].getTitle();
        db.transaction(function (tx) {
            tx.executeSql('update marker set position="'+pos+'" where title="'+title+'"');
        });
    }
}

But the code doesn't work. Can I fix this? Or should I change the logic ?

Aucun commentaire:

Enregistrer un commentaire