mardi 20 octobre 2015

Jquery Json Cordova issue

I'm having trouble with the following function. The purpose is to get data from a Json feed and add it to an offline database with jquery mobile. The database part works fine. The json part gets the data fine but can't add it to the database for some reason.

Could it be that the tx.executable method is not available from within the json function? If so, how do I get around this?

any ideas really appreciated!

function SyncDataQuery(tx) {
    tx.executeSql('DROP TABLE IF EXISTS Picato');
    tx.executeSql('CREATE TABLE IF NOT EXISTS Picato (id unique, date date,am_pm)');

    //code to get Json data from server.

$.ajax({
    url: 'http://url1 2 3',  //fake url.
    dataType: 'jsonp',
    jsonp: 'jsoncallback',
    timeout: 5000,
    success: function(data, status){

        $.each(data, function(i,item){
            var insId = parseInt(item.idservice);
            var insDate = item.date;
            var insTime = item.am_pm;
            //alert(insId + insDate + insTime);
            tx.executeSql('INSERT INTO Picato (id, date, am_pm) VALUES (insId, insDate,insTime)');
        });

    },
    error: function(){
        console.log('There was an error loading the data.');
    }
}); 

}

Aucun commentaire:

Enregistrer un commentaire