0

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

asked Feb 5, 2016 at 11:31
4
  • are you using mobile jquery in your app ? Commented Feb 5, 2016 at 12:26
  • No I'm using basic jquery and JavaScript.. Is any solution possible in jquery mobile? Commented Feb 6, 2016 at 4:31
  • yes in jquery mobile you can pass mobile loading in ajax call while sending and receiving data and you can manage progress bar. Commented Feb 6, 2016 at 5:05
  • Can you please provide any examples? Commented Feb 6, 2016 at 11:01

1 Answer 1

0

transaction is an asynchronous call. To make synchronous call, you can check this link and follow it's answer.

It will surely help you.

answered Feb 5, 2016 at 12:34
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.