2011-07-24 141 views
0

我正在使用Fancybox在我的網站上顯示模式。這種模式每次從新聞稿的評論中加載10條評論。我比jquery和ajax不太熟練,並且想獲得一些幫助,因爲我無法按照需要使用它。jquery Fancybox重新加載模式內容

顯示信息是沒有問題的,但是我遇到的問題是我似乎無法讓它顯示除第一頁評論以外的任何內容。

我使用觸發模式代碼:

<script type="text/javascript"> 
    $(document).ready(function() { 

     $("a.comments").fancybox(); 
     }); 

模態使用下面的鏈接觸發罰款:

<a class="comments" href="./process/news.php?n='.$news['id'].'&page=1">View Comments/Add Comment ('.$comments_total.')</a> 

模態顯示下面的代碼:

<?php session_start(); 
//no caching, we're using ajax 
header("Expires: 0"); 
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
header("cache-control: no-store, no-cache, must-revalidate"); 
header("Pragma: no-cache"); 

//base 
include ("../includes/config.php"); 
include ("functions.php"); 
checkLogin(); 

//variables 
$act = prepare($_GET['act']); 
$n = prepare($_GET['n']); 
$page = prepare($_GET['page']); 
$modal = $_POST['nyroModal']; 

//Possible pages 
switch($act) 
{ 
    default: 
    { 
    if(!empty($n)) 
    { 
     $css = '<link rel="stylesheet" href="stylesheets/Main.css">'; 
     $query = mysql_query("SELECT * FROM news WHERE id='$n'") or die(mysql_error() . "flap"); 
     if($query) 
     { 
     $news = mysql_fetch_array($query); 
     $_comments .= '<table width="98%" cellpadding="0" cellspacing="0" CLASS="postingnews">'; 

     if(empty($page)) 
     { 
      $page = "1"; 
     } 

     $total = mysql_num_rows(mysql_query("SELECT * FROM `news_comments` WHERE `newsid`='$n'")); 
     if($total < 1) 
     { 
      echo "No comments have been made yet."; 
     } 
     $total_pages = ceil($total/10); 
     //create pagination 
     if($page < $total_pages) 
     { 
      $next = $page +1; 
      $next = '<a class="comments" href="../process/news.php?n=' . $n . '&page=' . $next . '">Next</a>'; 
     } 
     if($page > 1) 
     { 
      $prev = $page - 1; 
      $prev = '<a class="comments" href="../process/news.php?n=' . $n . '&page=' . $prev . '">Previous</a>'; 
     } 
     $offset = ($page - 1) * 10; 
     $comments = mysql_query("SELECT * FROM `news_comments` WHERE `newsid`='$n' ORDER BY `id` ASC LIMIT $offset, 10"); 
     while($comment = mysql_fetch_assoc($comments)) 
     { 
      $_comments .= '<tr><td colspan="2" valign="top" class="newsrepeat3" style="border-bottom:1px solid black;"><b>Added By: <a href="profile.php?username='.$comment['username'].'">'.$comment['username'].'</a> '; 

     if($ui['rank'] == 'Senior Admin' || $ui['rank'] == 'Admin' || $ui['rank'] == 'Moderator') 
      { $_comments .= ' <a href="news.php?n='.$n.'&d='.$comment['id'].'"> - Delete Comment</a>'; } 

     $_comments .= '</b> 
     <br>'.stripslashes($comment['message']).'</td></tr>'; 

     } 
     if($_COOKIE['userid'] != "") 
     { 
      $text = ' 
      <form method="post" action="process/news.php?act=post" class="nyroModal"> 
       <textarea name="message" maxlength="200" style="width: 300px; height: 85px"></textarea><br /> 
       <input type="hidden" name="newsid" value="' . $n . '" /> 
       <input type="submit" value="reply" /> 
      </form> 
      '; 
     } 
     $_comments .= '</table>'; 
     echo ' 
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
      <html xmlns="http://www.w3.org/1999/xhtml"> 
      <head> 
       ' . $css . ' 
      </head> 
      <body style="margin: 0px; padding: 0px;"> 
     <div class="comments_div"> 
       <table cellspacing="0" cellpadding="0" border="0" width="98%"> 
       <tr><td colspan="2"> ' . $_comments . '</td></tr> 
       <tr> 
       <td align="left" width="49%">' . $prev . '</td> 

       <td align="right" width="49%">' . $next . '</td> 
       </tr> 
       <tr><td colspan="2" align="center"> 
       ' . $text . ' 
       </td></tr> 
       </table> 
     </div> 
      </body> 
      </html> 
     '; 
     } 
    } 

    break; 
    } 
    case 'post': 
    { 
    //post news comment  
    $message = format($_POST[message]); 
    if(!empty($message)) 
    { 
     //check if underage 
     if($ui[underage] == 'yes') 
     { errormsg('Sorry but you are underage and cannot use this feature.', 'news.php', 'Go Back'); } 
      $n = $_POST['newsid']; 
     mysql_query("INSERT INTO `news_comments` (`newsid`, `username`, `message`) VALUES('$n', '$ui[username]', '$message') "); 
     echo '<p align="center" style="font-weight: bold;">Thank you for your reply!</p>'; 
    } 
    break; 
    } 
} 
?> 

但是,當我點擊鏈接轉到下一頁的評論時,它什麼也不做。我需要做些什麼才能使它重新加載下一頁的評論模式?

回答

0

可以使用的onComplete選項到下一個頁面綁定:

$("a.comments").fancybox({ 
    type: 'ajax', 
    onComplete: function(){ 
     $("#fancybox-content a.comments").fancybox(); 
    } 
});