17 Jquer定时刷新以及循环遍历功能和ajax 的异步请求数据

var myrefresh=function(){
// 获取选择的赛事ID
var arr=[]; // 定义数组存储结束信息内容
var arr1=[]; // 定义数组存储未开始的数据
var competitionId=(‘#id option:selected’).val();(“#content tbody tr”).each(function(){
var bgc=(this).attr(“style”);  
              if(bgc==”background: #BBFF66;” || bgc==”background: rgb(187, 255, 102) none repeat scroll 0% 0%;”){  
                 arr.push($(this).attr(“id”));  
              }  
              if(bgc==undefined){  
                arr1.push($(this).attr(“id”));  
              }  
})  
// 异步刷新数据
.ajax({
url:’{ctx}/summary/showDataJson.shtml?strList=’+arr+’&strList1=’+arr1,  
            dataType : ‘JSON’,  
            type:’POST’,  
            data :{‘competitionId’:competitionId},  
            success : function(result){  
            if(result.flg==true){  // 说明后台查询到数据  
                    jQuery.each(result.idList, function(i,item){
(“#content tbody tr”).each(function(){
var trId=(this).attr(“id”);  
                          if(trId==item){
(“#”+trId).css(‘background’,’#FFCC22’);
}
})
});
jQuery.each(result.idList1, function(j,item1){
(“#content tbody tr”).each(function(){  
                          var  trId=
(this).attr(“id”);
if(trId==item1){
(“#”+trId).css(‘background’,’#BBFF66’);  
                          }  
                     })   
                   });  
               }  
            else{  
                 jQuery.each(result.idList1, function(j,item1){
(“#content tbody tr”).each(function(){
var trId=(this).attr(“id”);  
                          if(trId==item1){
(“#”+trId).css(‘background’,’#BBFF66’);
}
})
});
}
}
});

}
setInterval(‘myrefresh()’,15000); // 设置15秒刷新ajax 方法

你可能感兴趣的:(jquery,ajax)