vendredi 5 février 2016

Progress bar to download data SQLITE javascript

I have a scenario where I have to show a progress bar to load data to sqlite from online server.I am loading a few master tables and transaction tables. I have created the sqlite tables and then called ajax to get data and have loaded in sqlite:

 insert_sur_category(function(ret_insSur)
{
    //calls ajax gets data from php and then inserts into sqlite using foreach loop and insert command
    if(ret_insSur=="success")
    {
        insert_districts(function(ret_dis)
        {
}
}
}

sample ajax code

function insert_sur_category(callBack){
//alert("ding here");
var i;
var separator='surveymaster';
//alert(sessionStorage.url+"load_masters.php?separator="+separator);
 $.ajax({        
     type: "POST",
     url: sessionStorage.url+"load_masters.php?separator="+separator,       
     contentType: "application/json; charset=utf-8",
     dataType: "json",

     success: function(data){
        obj = JSON.stringify(data);
        obj1 = JSON.parse(obj); 

        if(obj1!=0)
        {       

        var i=0;

             $.each(data, function(i, item) {
             myDB.transaction(sur_category);

            function sur_category(tx){
                        tx.executeSql('INSERT INTO survey_category (sur_category_id, sur_category_name,last_updated) VALUES("'+obj1[i].id+'","'+obj1[i].name+'",datetime())');
            }
                //  sur1(); 
        //callBack("success");
                });

        sur1(); 
        callBack("success");    
        }
        else
        {
            //alert("sdfdsf");
            callBack("failed");
        }

     },
        complete: function(){

        }

    });  
 }   

After all callbacks are success I have given a alert to say data loaded successfully.However the alert comes long before the data is loaded.I am checking using google chrome.Any help Please

Aucun commentaire:

Enregistrer un commentaire