javascript - ajax异步请求数据,ios屏幕闪动
PHP中文网
PHP中文网 2017-04-11 13:32:17
0
1
641

做一个聊天页面,ajax异步请求数据时,不论有无数据返回,ios都会闪动一下,而android不会闪动 ,这是怎么回事,该如何解决

$(document).ready(function(){
        $('.loading_box').attr('style','display:none');
        ajaxform();
        window.setInterval("ajaxform()",3000); 

    });
    

function ajaxform(){
    var id=$(".main_box ul li:last-child").find('.delete_btn').attr('field');//alert(id);
    $.post(
        "{:U('App/Friends/ajaxform')}",
        {"openid":openid,"id":id},
        function(data){
          if (data) {
            var str = "";console.log(data);
            $.each(data, function(index, array) {
              if(array['openid']==openid){
                if(array['type']==0){
                  //普通文字或图片
                  str='<li class="chart-right"><p class="chart_text_box"><p class="jieshao"><p>'+array['uname']+'</p><p>'+array['time']+'</p></p><p class="chart_text_qipao_right"><p>'+array['content']+'</p></p><p class="operation_box"><p class="delete_btn" field="'+array['id']+'">删除</p></p></p><p class="persion_img_right"><img src="'+array['headimgurl']+'"><font><img src="{$tpl}App/Friends/Public/img/vipv'+array['classid']+'l.png"></font></p></li>';
                }else{
                  //我的霸屏
                  str='<li class="chart-right"><p class="chart_text_box"><p class="jieshao"><p>'+array['uname']+'</p><p>'+array['time']+'</p></p><p class="chart_text_qipao_right"><p><i class="money_text">重金霸屏'+arr[array['type']]+'秒</i>'+array['content'];
                  if(array['img']!=""){
                    str+='<font class="chart_img"><img src="'+array['img']+'"></font>';
                  }
                  str+='</p></p><p class="operation_box"><p class="delete_btn" field="'+array['id']+'">删除</p></p></p> <p class="persion_img_right"><img src="'+array['headimgurl']+'"><font><img src="{$tpl}App/Friends/Public/img/vipv'+array['classid']+'l.png"></font></p> </li>';
                }  
              }else{
                if(array['type']==0){
                  //普通文字或图片
                  str = ' <li class="chart-left"><p class="persion_img_left"><img src="'+array['headimgurl']+'"><font><img src="{$tpl}App/Friends/Public/img/vipv'+array['classid']+'l.png"></font></p> <p class="chart_text_box"><p class="jieshao"><p>'+array['uname']+'</p><p>'+array['time']+'</p></p><p class="chart_text_qipao_left"><span class="sanjiao_left"></span><p>'+array["content"]+'</p></p>';
                  if(isadmin){
                    str+='<p class="operation_box"><p class="delete_btn" field="'+array['id']+'">删除</p> <p class="blacklist" field="'+array['openid']+'">拉黑</p></p>';
                  }
                  str+='</p> </li>';
                }else{
                  //他人霸屏
                  str='<li class="chart-left "><p class="persion_img_left"><img src="'+array['headimgurl']+'"><font><img src="{$tpl}App/Friends/Public/img/vipv'+array['classid']+'l.png"></font></p> <p class="chart_text_box"><p class="jieshao"><p>'+array['uname']+'</p><p>'+array['time']+'</p></p><p class="chart_text_qipao_left"><span class="sanjiao_left"></span><p><i class="money_text">重金霸屏'+arr[array['type']]+'秒</i>'+array['content'];
                  if(array['img']!=""){
                    str+='<font class="chart_img"><img src="'+array['img']+'"></font>';
                  }
                  str+='</p></p>';
                  if(isadmin){
                    str+='<p class="operation_box"><p class="delete_btn" field="'+array['id']+'">删除</p> <p class="blacklist" field="'+array['openid']+'">拉黑</p></p>';
                  }
                  str+='</p> </li>';
                }
              }
              $(".main_box ul").append(str);
              $('.main_box').scrollTop( $('.main_box')[0].scrollHeight );
            });
          }
                     
        }
    );
}
PHP中文网
PHP中文网

认证0级讲师

Antworte allen(1)
Peter_Zhu

闪动是页面刷新了,看是否有重新渲染页面的代码。

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage