在完全读取响应之前,Ajax加载器已停止 [英] Ajax loader stopped before reading the response completely

查看:76
本文介绍了在完全读取响应之前,Ajax加载器已停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过服务从服务器获取数据并需要将它们写入Localdatabse,以便下次我不需要再次从服务器获取数据.Eveerthing工作正常。我的问题是在阅读我需要的响应时显示请稍候消息,因为将要插入大量的记录。我尝试了以下代码,显示Loader gif的持续时间很短。我希望Loader应该显示到最后一条记录插入。帮助我。

 jQuery( #search_content) .css(  display  none); 
jQuery( #div_loader)。css( display block );
jQuery.ajax({
type: 获取
url:serviceurl + / getalldata
contentType: application / json; charset = utf-8
dataType: json
async true
// data:{user_id:id},
成功:函数(响应)
{

如果(响应!= ' '
{


// 从响应和st读取内容将其存入新创建的表

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 );
jQuery( #search_content)。css( display block );
// $ .unblockUI();
}

else
{
alert(' 接收数据时遇到一些问题。请稍后再检查。);
}


}
});









 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,air_airport,companion,aircrat_type,tail_num)VALUES(' + first_name + ' ,' + last_name + ' ,' +电子邮件+ ' ,' + company + ' ,' + city + ' ,' +州+ ' ,' +国家/地区+ ' ,' + 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 = < span class =code-keyword><?php echo base_url();?> assets / images / loader123.gif alt = CJP title = CJP / >
< / div >

解决方案

.unblockUI();
}

< span class =code-keyword> else
{
alert(' 接收数据时遇到一些问题。请稍后再检查。');
}


}
});









 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,air_airport,companion,aircrat_type,tail_num)VALUES(' + first_name + ' ,' + last_name + ' ,' +电子邮件+ ' ,' + company + ' ,' + city + ' ,' +州+ ' ,' +国家/地区+ ' ,' + 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 = < span class =code-keyword><?php echo base_url();?> assets / images / loader123.gif alt = CJP title = CJP / >
< / div >


这是已知错误 [ ^ 。我遇到过这个问题并尝试了几乎所有的解决方法都在网上但没有任何工作完美。



您可以尝试使用 spin.js [ ^ ]。它几乎适用于所有浏览器。



希望有帮助!


直接在for循环中添加插入..

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,
        //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.');
            }


        }
    });





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>

解决方案

.unblockUI(); } 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>


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!


Added insertion directly inside the for loop..


这篇关于在完全读取响应之前,Ajax加载器已停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆