ajax无刷新分页,支持id定位_PHP教程

WBOY
发布: 2016-07-13 17:37:14
原创
955 人浏览过

Header("Content-Type:text/html; charset=utf-8");
// AK QQ:42220796
// 总数 单页条数 当前页 点击后的url地址get 应用的js函数  显示几个  显示的地址
function AjaxPage($Total,$ListNub,$CurrentPage,$Url,$AjaxAction,$HalfPer=,$ViewId=)
{
//计算总页数
$totalPage = @ceil($Total/$ListNub);
$total=$totalPage-1;
$re="";

//echo $CurrentPage;
$re .= ( $CurrentPage > 0 )
?
"

href="javascript:$AjaxAction($Url=0,$ViewId)"">首页 href="javascript:$AjaxAction(".$Url."=".($CurrentPage-1).",$ViewId)"">上一页 "
:
"首页 上一页 ";
for ( $i =
$CurrentPage - $HalfPer,$i > 0 || $i = 0 ,     $j =
$CurrentPage + $HalfPer, $j )
{
  $re .= $i == $CurrentPage
  ?
"[" . ( $i + 1 ) .
"]
"
  : "href="javascript:$AjaxAction($Url=$i,$ViewId)">" . ( $i + 1 ) .
"
";
}
$re .= ( $CurrentPage )
? "href="javascript:$AjaxAction(".$Url."=".($CurrentPage+1).",$ViewId)"">下一页 href="javascript:$AjaxAction(".$Url."=".($total).",$ViewId)"">尾页 "
:
"下一页 尾页 ";
$re="style=text-align:center>$re
";
return
$re;

}
//总页数,传递的页面变量-当前页 url地址 前后各多少页
$page = $_GET[page];
//echo
page(10,$page,index.php?page,2);


?>


echo
AjaxPage(200,20,$page,rand.php?page,ajaxaction,2,nike);
?>


function send_request(url,htmlid) {
http_request =
false;
if (window.XMLHttpRequest) {
  http_request = new
XMLHttpRequest();
  if (http_request.overrideMimeType)
{
   http_request.overrideMimeType(text/xml);
  }
}
else if (window.ActiveXObject) {
  try
{
   http_request = new
ActiveXObject("Msxml2.XMLHTTP");
  } catch (e)
{
   try {
    http_request = new
ActiveXObject("Microsoft.XMLHTTP");
   } catch (e)
{}
  }
}
if (!http_request)
{
  alert(不能创建 XMLHttpRequest 对象!);
  return
false;
}
http_request.onreadystatechange = function
(){likeakak(htmlid);}//processRequest(htmlid)
http_request.open(GET,
url, true);
http_request.send(null);

}

//处理返回信息
function processRequest(htmlid) {
if
(http_request.readyState == 1)
{
  document.getElementById(htmlid).innerHTML="下载中...";
}
if
(http_request.readyState == 4) {
  if (http_request.status == 200)
{
   document.getElementById(htmlid).innerHTML=http_request.responseText;
  }
else
{
   alert(请求异常);
  }
}
}
//处理返回信息
function
likeakak(htmlid)
{
if (http_request.readyState == 1)
{
  document.getElementById(htmlid).innerHTML="下载中...";
}
if
(http_request.readyState == 4) {
  if (http_request.status == 200)
{
   document.getElementById(htmlid).innerHTML=http_request.responseText;
  }
else
{
   alert(请求异常);
  }
}
}
function
ajaxaction(url,viewid)
{
send_request(url,viewid);
}

//自定义调用函数
function elist(id)
{
var inputarray = new
Array();

inputarray[1] = aaa;
inputarray[2] =
bbb;
inputarray[3] = ccc;
inputarray[4] =
ddd;
inputarray[5] = eee;

send_request(ajax.php?do=ajax&sort=+id,inputarray[id]);

}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/486598.htmlTechArticle?php Header("Content-Type:text/html; charset=utf-8"); // AK QQ:42220796 // 总数 单页条数 当前页 点击后的url地址get 应用的js函数 显示几个 显示的地址 fun...
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板