虚心使人进步

虚心学习,天天向上......
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

经典的ajax遍历循环

Posted on 2020-10-16 21:46  Showker  阅读(1034)  评论(0编辑  收藏  举报

<textarea name="filter" style="display:none"><{$filter}></textarea>
<div class="division">
<div class="notice"><{t}>共需同步<{/t}><strong><{$editInfo|count}></strong><{t}>条数据。<{/t}><br>小提示:同步过程中请不要关闭窗口
</div>
<table border="0" cellpadding="0" cellspacing="0" id="tongbumembers">

<tr>
<th style="text-align:center">
序号
</th>

<th style="text-align:center">
注册时间
</th>

<th style="text-align:center">手机号
</th>

<th style="text-align:center">同步结果
</th>

</tr>
<{foreach from=$editInfo item=item key=key name="foo"}>

<{if $item.mobile!=""}>
<tr>

 


<td style="text-align:center"><{$smarty.foreach.foo.iteration}></td>
<td style="text-align:center"><{$item.regtime|cdate:FDATE_FTIME}></td>
<td style="text-align:center"><{input class="tongbumobile" member_id="{$item.member_id}" type="hidden" name="mobiles[{$item.member_id}]" value=$item.mobile}><{$item.mobile}></td>

<td id="tongburesult_<{$item.member_id}>" style="font-weight:bold" ></td>
</tr>
<{/if}>
<{/foreach}>
</table>
</div>
<{area inject=".mainFoot"}>
<center>
<{button label="同步" type="button" id="batch_edit_btn"}>
</center>
<{/area}>

<script>
$('batch_edit_btn').addEvent('click',function(){
$('batch_edit_btn').set('html','正在同步中,请稍候....')

var allrows=$ES('#tongbumembers .tongbumobile');
var allrowslength=allrows.length;

var currentIndex=0;//退出递归的条件变量
function newRequest(){
if(currentIndex>=allrowslength){ //infos是存放主机名称的数组
MessageBox.success('同步结束');
// window.finderDialog.close();
$('batch_edit_btn').set('html','同步结束');
return;
}
var item = allrows[currentIndex];
new Request({
'url':'index.php?ctl=<{$env.get.ctl}>&act=saveTongBu&r='+Math.random(),
'data':{'member_id':item.get('member_id'),'mobile':item.value},
'method':'post',
onSuccess:function(r){
currentIndex++;
r=eval('('+r+')');
if(r.status=='exist'){
$('tongburesult_'+item.get('member_id')).set('html',
'<span style="color:#F00">×库里已存在</span>');
}
else if(r.status=='success'){
$('tongburesult_'+item.get('member_id')).set('html',
'<span style="color:#6db248">√同步成功');
}
else if(r.status=='failed'){
$('tongburesult_'+item.get('member_id')).set('html',
'<span style="color:#F00">×插入失败'+r.error_msg);
}

else{
$('tongburesult_'+item.get('member_id')).set('html',
'<span style="color:#F00">×手机号检测结果</span>'+r.status); 
}

newRequest();
}
}).send();
}
newRequest();


//window.finderDialog.close();
});
</script>