lundi 28 septembre 2015

Insert data from Json in local storage

Now (for one Table) I call url get Json string and insert in local storage,

It is possible create one json for all table (all sql table car,users,country) and that insert in local storage (SQL LITE)....

Any example or solution? My example one json for one table.

1("[    {\"carCode\":\"1\",\"carType\":\"2 \",\"carName\":\"AUDI\"},
{\"carCode\":\"2\",\"carType\":\"2 \",\"carName\":\"BMW\"},
{\"carCode\":\"3\",\"carType\":\"2 \",\"carName\":\"WV\"},");

...

function callJsonSync(userName, procedureName, jsonCallBackFunc) {

    $.ajax({

        crossDomain: true,
        type: "GET",
        contentType: "application/json; charset=utf-8",
        async: false,
        url: "http://ift.tt/1O4LC4i?",
        data: { userName: userNameVal, procedureName: procedureNameVal },
        dataType: "jsonp",
        jsonpCallback: jsonCallBackFunc,

        error: function (xhr, textStatus, errorThrown) {
        }
    });
}

//////////

function loadDataSync() {
    callJsonSync('myLocalDB', 'wsCarSync', 'loadAction')
}
function loadAction(data) {

    var db = myLocalDB.webdb.db;
    if (data !== undefined) {
        var obj = jQuery.parseJSON(data);
        var objCount = obj.length;
        var rowsCount = 1
        $.each(obj, function (key, value) {

            db.transaction(function (tx) {
                tx.executeSql("INSERT INTO car (carCode, carType, carName, carDescription) VALUES (?,?,?,?)",
                        [value.carode, value.carType, value.carName, value.carDescription],
                        function () {

                        },
                        myLocalDB.webdb.onError);
            });


        });
    }
    else {

    }
}

Aucun commentaire:

Enregistrer un commentaire