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
-
are you using mobile jquery in your app ?Jay Rathod– Jay Rathod2016年02月05日 12:26:32 +00:00Commented Feb 5, 2016 at 12:26
-
No I'm using basic jquery and JavaScript.. Is any solution possible in jquery mobile?Philomath– Philomath2016年02月06日 04:31:52 +00:00Commented 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.Jay Rathod– Jay Rathod2016年02月06日 05:05:37 +00:00Commented Feb 6, 2016 at 5:05
-
Can you please provide any examples?Philomath– Philomath2016年02月06日 11:01:29 +00:00Commented Feb 6, 2016 at 11:01
1 Answer 1
transaction is an asynchronous call. To make synchronous call, you can check this link and follow it's answer.
It will surely help you.