I have get the data's from the server through service and need to write them into Localdatabse,so that next time i dont need to fetch data from server again.Eveerthing works fine.My problem is in while reading the response i need to show "Please wait " message since there will be huge amount of records to be inserted.I tried the following code which displays Loader gif for small duration of time.I want the Loader should get displayed till the last record insertion.Help me.
jQuery("#search_content").css("display", "none");
jQuery("#div_loader").css("display", "block");
jQuery.ajax({
type: "Get",
url: serviceurl + "/getalldata",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (response)
{
if (response != '')
{
var res = eval(response);
for (var i = 0; i < res.users.length; i++)
{
var first_name = res.users[i].firstname;
var last_name = res.users[i].lastname;
var email = res.users[i].email;
var company = res.users[i].company;
var city = res.users[i].city;
var state = res.users[i].state;
var country = res.users[i].country;
var cell = res.users[i].cell;
var age = res.users[i].age;
var v1 = res.users[i].value1;
var v2 = res.users[i].value2;
var v3 = res.users[i].value3;
insert_users_table(first_name,last_name,email,company,city,state,country,cell,age,v1,v2,v3);
}
jQuery("#div_loader").css("display", "none");
jQuery("#search_content").css("display", "block");
}
else
{
alert('Some Problem in receiving data.Please Check again later.');
}
}
});
function insert_users_table(first_name,last_name,email,company,city,state,country,cell,age,v1,v2,v3)
{
var dbinsert = window.openDatabase("CJP_DB", "1.0", "CJP_DB", 2 * 1024 * 1024);
var qry = 'INSERT INTO users (first_name,last_name,email,company,city,state,country,cell,home_airport,companion,aircrat_type,tail_num) VALUES ("' + first_name + '","' + last_name + '","' + email + '","' + company + '","' + city + '","' + state + '","' + country + '","' + cell + '","' +age + '","' + v1+ '","' + v2 + '","' + v3 + '")';
dbinsert.transaction(function insertprofileDB(tx)
{
tx.executeSql(qry);
}, errorCB);
}
<div id="div_loader" class="searchdiv" style="display:none;">
<img src="<?php echo base_url();?>assets/images/loader123.gif" alt="CJP" title="CJP" />
</div>