Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C#
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,
        //data: { user_id: id },
        success: function (response)
        {

            if (response != '')
            {


                //read the contents from response and stored it into newly created table

                var res = eval(response);
                //alert(res.users.length);
                //var i = 0;
                //while (i < res.users.length)

                for (var i = 0; i < res.users.length; i++)
                {
                    //var id = res.users[i].id;
                    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);


                    //i++;
                }

                jQuery("#div_loader").css("display", "none");
                jQuery("#search_content").css("display", "block");
                //$.unblockUI();
            }

            else
            {
                alert('Some Problem in receiving data.Please Check again later.');
            }


        }
    });




C#
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);
}


XML
<div id="div_loader" class="searchdiv" style="display:none;">
              <img src="<?php echo base_url();?>assets/images/loader123.gif" alt="CJP" title="CJP" />
            </div>
Posted
Updated 20-Mar-14 0:19am
v6

It's a known bug[^]. I have had this issue and tried almost everything workaround on web but nothing worked perfectly.

You may try using spin.js[^]. It works well with almost all browsers.

Hope that helps!
 
Share this answer
 
Comments
Ankur\m/ 18-Mar-14 12:32pm    
All details are very well explained in the given link. Let me know where you have problem.
Ramkumar K 20-Mar-14 6:11am    
i tried those steps,its not working for me.. :(
Ankur\m/ 20-Mar-14 8:26am    
Spin.js is not working?
Added insertion directly inside the for loop..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900