我还有一个问题困扰我多天啊,不知道怎么解决,请问是否有高手可以帮助解决
还是一个Ajax程序,是这样的用Ajax获得TEXT的内容然后显示到页面上,TEXT中有分页的,然而失效了,我事先在别处用就好好的Ajax程序如下
function listPageComments(main_channel,second_channel,page,url){//其中page代表当前页面var data="main="+main_channel+"&second="+second_channel+"&page="+page;CreateAjax();xmlHttp.onreadystatechange=listPageCallBack;xmlHttp.open("POST",url+"?r="+new Date().getTime(),true);xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');xmlHttp.send(data);return false;}function listPageCallBack(){if(xmlHttp.readyState==4){if(xmlHttp.status==200){document.getElementById("pinglun").innerHTML=xmlHttp.responseText;}}}PHP文件的程序如下cmmon_class.php
abstract class pages {
protected $total; //记录总数  protected $page; //第几页,如果记录数为空时$page=0这是必然的  protected $pagesize; //每页显示记录数,缺省为10  protected $url; //分页导航链接  public $firstp; //第一页  public $nextp; //下一页  public $prevp; //前一页  public $lastp; //最后一页  public $navop; //当前页面相关信息  function __construct($total,$page,$pagesize=10,$url="") {//构造函数  $this->total = $total;  $this->page = $page;  $this->pagesize = $pagesize;  $this->url = $url;  $this->firstp = "";  $this->nextp = "";  $this->prevp = "";  $this->lastp = "";  $this->navop = "";}  abstract function get_page_desible();
abstract function get_page_first();
abstract function get_page_next();
abstract function get_page_prev();
abstract function get_page_last();
abstract function get_page_nav();}
class ajax_page extends pages{//分页的类$nav就是返回的分页信息function __construct($total,$page,$pagesize=10,$url="",$main_channel,$second_channel){parent::__construct($total, $page,$pagesize,$url);$this->main_channel=$main_channel;$this->second_channel=$second_channel;}function get_page_desible() {// 附加页面信息  return $this->navop;  }  function get_page_first() {//第一页  return $this->firstp;  }  function get_page_next() {//后一页  return $this->nextp;  }  function get_page_prev() {//前一页  return $this->prevp;  }  function get_page_last() {//尾页  return $this->lastp;  }  
function get_page_nav(){//echo $this->second_channel;if (empty($this->url)||$this->url==""){$this->url=$_SERVER['REQUEST_URI'];}  $parse_url = parse_url($this->url);  $url_query = $parse_url["query"]; //得到查询部分  $currpath = $_SERVER["PHP_SELF"];  $url_query = eregi_replace("(page|&page)=$this->page","",$url_query);  $pagenum = (int) ceil($this->total / $this->pagesize); //总页数,也是最后一页数  $firstpage = 1; //第一页为1  $currpage = $this->page;  $lastpage = $pagenum ; /*最后一页依总页数而定,如果总页数为0,则最后一页也为零,否则最后一面为总页数值 */$prevpage = ($currpage - 1 > 0 ? $currpage - 1 : 1); /*如果当前页减小于或等于0时,那取$page值,$page可能取值为0 */
$nextpage = ($currpage + 1 > $lastpage ? $currpage : $currpage + 1);/*如果当前页加1大于总页数,则取当前页数值 */$nav = "<b> $currpage </b> / <b> $pagenum </b> 页 &nbsp;"; //总页数中的第几页  $nav .= "<b> $this->pagesize </b>条记录/每页 &nbsp;"; //每一页显示记录数  $nav .= "共有: <b> $this->total </b>条记录 &nbsp;"; //总共记录数  $this->navop = $nav;  //$document=$_SERVER['DOCUMENT_ROOT']."/CaoCao/list_page_comments.php";$document="127.0.0.1/CaoCao/list_page_comments.php"; 
$nav .= "<a id='afirst' href='#' onclick=\"listPageComments(".$this->main_channel.",".$this->second_channel.",".$firstpage.",'".$document."\")'>首页</a> &nbsp;"; //首页  /*我怀疑问题或许就出在这里*/$nav .= "<a id='anext' href='#' onclick=\"listPageComments(".$this->main_channel.",".$this->second_channel.",".$nextpage.",'".$document."\")'>下一页</a> &nbsp;"; //下一页  
for ($i = 1; $i <= $pagenum; $i++) {//循环显示所有页$nav .= "<a href='#' onclick=\"listPageComments(".$this->main_channel.",".$this->second_channel.",".$i.",'".$document."\")'>[&nbsp;<b>$i</b>&nbsp;&nbsp;]</a>&nbsp;"; //所有页的信息}$nav .= "<a id='aprev' href='#' onclick=\"listPageComments(".$this->main_channel.",".$this->second_channel.",".$prevpage.",'".$document."\")'>前一页</a> &nbsp;"; //前一页  $nav .= "<a id='alast' href='#' onclick=\"listPageComments(".$this->main_channel.",".$this->second_channel.",".$lastpage.",'".$document."\")'>尾页</a>"; //尾页  $this->firstp =$firstpage;  $this->nextp =$nextpage;  $this->prevp =$prevpage;  $this->lastp =$lastpage;  return $nav;
}}/*经过检查这个类是没有问题的*/处理页面如下list_page_comments.php
require_once ("include/common_class.php");//这里面有分页类和获得每个页面数据的类require_once "include/conn.php";//链接数据库的类require_once "inc/database.inc.php";//数据库配置$main=$_POST['main'];$second=$_POST['second'];$query="SELECT * FROM caocao_comments WHERE main_channel=".$main." and second_channel=".$second;$result=$conn->query($query) or die($query);$total=$result->num_rows;$now_page="";if (empty($_POST['page'])) {$now_page=1;}else {$now_page=intval($_POST['page']);}$page_size=1;$pages=new ajax_page($total, $now_page,$pagesize=1,$url="", 1, 2);//调用分页类$nav=$pages->get_page_nav();//获得分页信息$list_comment=new get_detailpage_array($server, $admin, $passwd, $database, $query, "ID");//获得每个页面的数据的类
$list_comment->page_size=$page_size;$list_comment->current_page=$now_page;$comments=$list_comment->get_array();//获得页面数据for ($i = 0; $i <count($comments); $i++) {$content.="<div><img src='../images/11.gif' width='25' height='23'/><span>".$comments[$i]['main']['UID']."</span>".$comments[$i]['main']['content']."<p>&nbsp;&nbsp;&nbsp;&nbsp; ".$comments[$i]['main']['date']."&nbsp;".$comments[$i]['main']['time']."&nbsp; &nbsp; <span><a href='#'>回复&nbsp;</a></span><span><a href='#'>删除</a></span></p></div>";}$content.="<div style='text-align:center; margin-top:10px;' >".$nav."</div>";echo $content;
 
然后在index_article.htm中调用ajax即在<body onload="listPageComments(1,2,1,'../list_page_comments.php')"></body>下面正常显示数据和分页,但是按分页按钮时却不显示相应的页面,效果如下
///////////////////////////////////////////////1曹操也来看你了
  2011-07-10 14:15:12 回复 删除1 / 3 页 1 条记录/每页 共有: 3 条记录 首页 下一页 [ 1 ] [ 2 ] [ 3 ] 前一页 尾页//////////////////////////////////////////////
就是说按了[1][2][3]这三个中的任意按钮前面的1/3页中的1没有变化,自然上面也没有变化了
我调试过ajax响应的页面即(list_page_comments.php)中////listPageComments(main_channel,second_channel,page,url)所有的参数都获得了
请高手帮助解决到底是怎么回事,说白了就是Ajax传过来的文本中listPageComments()失效了 

解决方案 »

  1.   

    括号用错了
    $nav .= "<a id='afirst' href='#' onclick=\"listPageComments(".$this->main_channel.",".$this->second_channel.",".$firstpage.",'".$document."\")'>首页</a> &nbsp;"; 
      

  2.   

    我该成这样了
    $nav .= "<a id='afirst' href='#' onclick=\"listPageComments(".$this->main_channel.",".$this->second_channel.",".$firstpage.",'".$document."')\">首页</a> &nbsp;"; //首页  $nav .= "<a id='anext' href='#' onclick=\"listPageComments(".$this->main_channel.",".$this->second_channel.",".$nextpage.",'".$document."')\">下一页</a> &nbsp;"; //下一页 
    for ($i = 1; $i <= $pagenum; $i++) {//循环显示所有页

    $nav .= "<a href='#' onclick=\"listPageComments(".$this->main_channel.",".$this->second_channel.",".$i.",'".$document."')\">[&nbsp;<b>$i</b>&nbsp;&nbsp;]</a>&nbsp;"; //所有页的信息 } $nav .= "<a id='aprev' href='#' onclick=\"listPageComments(".$this->main_channel.",".$this->second_channel.",".$prevpage.",'".$document."')\">前一页</a> &nbsp;"; //前一页  $nav .= "<a id='alast' href='#' onclick=\"listPageComments(".$this->main_channel.",".$this->second_channel.",".$lastpage.",'".$document."')\">尾页</a>"; //尾页 还是不行啊,分叶还是没有变化啊!
    到底是怎么回事呢,请高手帮助解答,多谢了!
      

  3.   

    整理了下你的代码,如下修改
    /*问题确实处在你构造的html上*///$document=$_SERVER['DOCUMENT_ROOT']."/CaoCao/list_page_comments.php";
    $document = "127.0.0.1/CaoCao/list_page_comments.php";
    $nav .= "<a id='afirst' href='#' onclick=\"listPageComments(" . $this->main_channel . "," . $this->second_channel . "," . $firstpage . ",'" . $document . "')\">首页</a> &nbsp;"; //首页 
    $nav .= "<a id='anext' href='#' onclick=\"listPageComments(" . $this->main_channel . "," . $this->second_channel . "," . $nextpage . ",'" . $document . "')\">下一页</a> &nbsp;"; //下一页  
    for ($i = 1; $i <= $pagenum; $i++) { //循环显示所有页
        $nav .= "<a href='#' onclick=\"listPageComments(" . $this->main_channel . "," . $this->second_channel . "," . $i . ",'" . $document . "')\">[&nbsp;<b>$i</b>&nbsp;&nbsp;]</a>&nbsp;"; //所有页的信息
    }
    $nav .= "<a id='aprev' href='#' onclick=\"listPageComments(" . $this->main_channel . "," . $this->second_channel . "," . $prevpage . ",'" . $document . "')\">前一页</a> &nbsp;"; //前一页  
    $nav .= "<a id='alast' href='#' onclick=\"listPageComments(" . $this->main_channel . "," . $this->second_channel . "," . $lastpage . ",'" . $document . "')\">尾页</a>"; //尾页  
      

  4.   

    大家看,返回的$nav是这样的
    ///////////////////////////////////////////////////////
     1 / 3 页   1 条记录/每页  共有: 3 条记录  首页  下一页  [ 1  ] [ 2  ] [ 3  ] 前一页  尾页
    /////////////////////////////////////////////////////
    从网页上看到的代码是这样的
    <b> 1 </b> / <b> 3 </b> 页 &nbsp;<b> 1 </b>条记录/每页 &nbsp;共有: <b> 3 </b>条记录 &nbsp;<a id='afirst' href='#' onclick="listPageComments(1,2,1,'127.0.0.1/CaoCao/list_page_comments.php')">首页</a> &nbsp;<a id='anext' href='#' onclick="listPageComments(1,2,2,'127.0.0.1/CaoCao/list_page_comments.php')">下一页</a> &nbsp;<a href='#' onclick="listPageComments(1,2,1,'127.0.0.1/CaoCao/list_page_comments.php')">[&nbsp;<b>1</b>&nbsp;&nbsp;]</a>&nbsp;<a href='#' onclick="listPageComments(1,2,2,'127.0.0.1/CaoCao/list_page_comments.php')">[&nbsp;<b>2</b>&nbsp;&nbsp;]</a>&nbsp;<a href='#' onclick="listPageComments(1,2,3,'127.0.0.1/CaoCao/list_page_comments.php')">[&nbsp;<b>3</b>&nbsp;&nbsp;]</a>&nbsp;<a id='aprev' href='#' onclick="listPageComments(1,2,1,'127.0.0.1/CaoCao/list_page_comments.php')">前一页</a> &nbsp;<a id='alast' href='#' onclick="listPageComments(1,2,3,'127.0.0.1/CaoCao/list_page_comments.php')">尾页</a>
    //////////////////////////////////////////////////
    从生成的代码看,看不出任何问题啊,我真不知道这是怎么回事啊?
      

  5.   

    127.0.0.1/CaoCao/list_page_comments.php 这个页面确实能收到你穿过去的三个值么?
      

  6.   

    向大家报喜了,我终于发现问题的所在了,原来是
    listPageComments(1,2,1,'127.0.0.1/CaoCao/list_page_comments.php')中的'127.0.0.1/CaoCao/list_page_comments.php'路径不行,我把它改成‘../list_page_comments.php’就正常了,但是我就搞不懂了,问什么相对路径可以,而绝对路径就不行了呢?