第五步:实现backend.php
backend.php文件用于接收前台的ajax请求,并返回xml格式的消息。其内容如下:
以下为引用的内容: <?php include("config.php"); header("Content-type: text/xml"); header("Cache-Control: no-cache"); foreach($_POST as $key => $value) if(@$action == "postmsg") echo "<?xml version=\"1.0\"?>\n"; |
前台会从backend.php得到xml相应,并解码xml文件显示在页面上。
第六步:用样式显示消息
用户每次载入页面,我们应在页面上显示旧的消息。因此,我们需要查询数据库以便得到旧的消息并显示他们:
以下为引用的内容: <div id="messagewindow"> <?php include("config.php"); // prepare the query string $query = "SELECT id, message, DATE_FORMAT(date, ‘%Y-%m-%d‘) ". "FROM message ". "ORDER BY id DESC "; // execute the query // if the guestbook is empty show a message while($row = mysql_fetch_array($result)) $message = htmlspecialchars($message); $message = nl2br($message); echo "<li><p class=‘info‘>Added on $date :</p>"; |
这些代码也位于在index.php中,同样,我们应用CSS定义一个漂亮的消息显示:
以下为引用的内容: #comments, #comments li{ margin:0; padding:0; list-style:none; } #comments li{ padding:.5em; margin:.5em 0; background:#fcfcfc; border:1px solid #e1e1e1; } #comments li .info{ padding:.2em 20px; background:#f1f1f1 url(images/ico_comments.gif) no-repeat 2px 50%; margin:0; color:#333; font-family:Georgia, "Times New Roman", Times, serif; } #comments li .body{ padding:.5em 20px; } #commentForm { width: 550px; } #messagewindow { |
现在,在我们添加一个新的更新后,页面看起来如下:
分页: [1] [2] [3] [4] [5]
TAG: TWITTER JQUERY 站点