AJAX获取数据并分页显示
<ul class="movList" id="datalist"> </ul> <div id="multi_page"> </div> <script language="javascript">var pagesize=20;var curr_page=1;var count=1;var setpages=6;var multipage="";function data(page){ jQuery("#datalist").html('<div id="loading"><img src="/Public/images/loading_circle.gif" width="50" height="54" />载入中,请稍等,因访问量巨大,列表将在2秒左右打开……</div>'); jQuery.getJSON('http://api.baomihua.com/video/GetChannelVideo?userid=11662088&channelid=657&pageid='+page+'&domain=v.zhiyin.cn&num='+pagesize+'&jsoncallback=?', function(data) { var html=""; jQuery.each(data.ChannelVideo, function(key, val) { html+="<li><a class=\"playpic\" href=\"/playbmh.php?videoid="+val.videoid+"\" target=\"_blank\"><b><img src=\""+val.videoimglink+"\"/></b></a><p class=\"mov-title\"><a title=\""+val.videotitle+"\" href=\"/playbmh.php?videoid="+val.videoid+"\" target=\"_blank\">"+val.videotitle+"</a></p></li>"; }); count=data.VideoNum; curr_page=page; jQuery("#datalist").html(html); //pages var multipage=""; if(count > pagesize) { pagem = setpages+1; offset = Math.ceil(setpages/2-1); pages = Math.ceil(count / pagesize); //if (defined('IN_ADMIN') && !defined('PAGES')) define('PAGES', pages); from = curr_page - offset; to = curr_page + offset; more = 0; if(pagem >= pages) { from = 2; to = pages-1; } else { if(from <= 1) { to = pagem-1; from = 2; } else if(to >= pages) { from = pages-(pagem-2); to = pages-1; } more = 1; } multipage += '<a class="a1">'+count+'条</a>'; //alert(curr_page); if(curr_page>0) { prepage=Math.max(curr_page-1,1); nextpage=Math.min(curr_page+1,pages); multipage += ' <a href="#" onclick="data('+prepage+')" class="a1">上一页</a>'; if(curr_page==1) { multipage += ' <span>1</span>'; } else if(curr_page>6 && more) { multipage += ' <a href="#" onclick="data(1)">1</a>..'; } else { multipage += ' <a href="#" onclick="data(1)">1</a>'; } } for(i = from; i <= to; i++) { if(i != curr_page) { multipage += ' <a href="#" onclick="data('+i+')">'+i+'</a>'; } else { multipage += ' <span>'+i+'</span>'; } } if(curr_page<pages) { if(curr_page<pages-5 && more) { multipage += ' ..<a href="#" onclick="data('+pages+')">'+pages+'</a> <a href="#" onclick="data('+nextpage+')" class="a1">下一页</a>'; } else { multipage += ' <a href="#" onclick="data('+pages+'">'+pages+'</a> <a href="#" onclick="data('+nextpage+')" class="a1">下一页</a>'; } } else if(curr_page==pages) { multipage += ' <span>'+pages+'</span> <a href="#" onclick="data('+curr_page+')" class="a1">下一页</a>'; } else { multipage += ' <a href="#" onclick="data('+pages+')">'+pages+'</a> <a href="#" onclick="data('+nextpage+')" class="a1">下一页</a>'; } } jQuery("#multi_page").html(multipage); //pages end });}data(curr_page);</script>
<div id="loading"><img src="/Public/images/loading_circle.gif" width="50" height="54" />载入中,请稍等,因访问量巨大,视频将在6秒左右打开……</div>
<iframe style="visibility:hidden" onreadystatechange=stateChangeIE(this) οnlοad=stateChangeFirefox(this) name="callframe" id="callframe" width="980" height="1300" frameborder="0" scrolling="no" marginheight="0" scrolling="no"></iframe>
<script language="javascript">
var videoid="<?php echo $videoid;?>";
var src = "http://video.baomihua.com/ssite/"+videoid+"&uid=48343307&istop=1";
function stateChangeIE(_frame)
{
if (_frame.readyState=="interactive")//state: loading ,interactive, complete
{
var loader = document.getElementByIdx_x_x("loading");
loader.innerHTML = "";
loader.style.display = "none";
_frame.style.visibility = "visible";
}
}
function stateChangeFirefox(_frame)
{
var loader = document.getElementByIdx_x_x("loading");
loader.innerHTML = "";
loader.style.display = "none";
_frame.style.visibility = "visible";
}
callframe.location.href=src;
</script>