include('inc/config.inc.php');
include('inc/dbclass.php');
$db=new db;//從數(shù)據(jù)庫操作類生成實例
$db->mysql($dbhost,$dbuser,$dbpassword,$dbname);//調(diào)用連接參數(shù)函數(shù)
$db->createcon();//調(diào)用創(chuàng)建連接函數(shù)
$addsql="insert into cr_fourm values(0,'$newfourm','$username','$time',$id)";
$db->query($addsql);
echo"<img src=images/pass.gif> <font color=red>評論已成功發(fā)表!</font>";
//echo $addsql;
$db->close();//關(guān)閉數(shù)據(jù)庫連接
?>
由于jsvascript采用UTF8編碼,在windows下采用ajax回送服務(wù)器的返回信息就會出現(xiàn)亂碼,因此在win下應(yīng)用開頭第一句是非常必要的。中間那段兩個包含文件是數(shù)據(jù)庫操作類和數(shù)據(jù)庫配置信息,我個人習慣將基本的數(shù)據(jù)庫操作寫成一個類,方便調(diào)用。到這里相信大家已經(jīng)基本明白這個程序的工作原理了,在給出頁面的HTML代碼:
代碼如下:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><?php echo $rows_p[p_info];?></td>
</tr>
<tr>
<td align="center"><br><br><iframe frameborder="0" scrolling="auto" src="showfourm.php?picid=<?=$id;?>" style=HEIGHT:250px;VISIBILITY:inherit;WIDTH:98%;Z-INDEX:2 ></iframe>
</td>
</tr>
<tr>
<td align="center"><br><br>
<div align="center" id="result"></div>
<form name="fourm">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25"> 快速發(fā)表評論<span class="STYLE1">(必須先登陸)用戶名:
<input name="username" type="text" value="<?=$username?>" readonly>
</span></td>
</tr>
<tr>
<td height="32" align="center" valign="middle"><textarea name="newfourm" class="f" id="newfourm"></textarea></td>
</tr>
<tr>
<td height="32"> <input name="submit" type="button" value="發(fā)表評論" onClick="checkfourm('result')">
<input name="reset" type="reset" id="reset" value="重新填寫">
<input name="id" type="hidden" id="id" value="<?php echo"$id";?>"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
這是我網(wǎng)頁的一部分,也就是實現(xiàn)這一功能的框架代碼,顯示評論的頁面用IFRAME(隱藏幀)調(diào)用,待信息發(fā)送完之后,只刷新IFRAME那一塊就可以看到自己發(fā)的評論,從發(fā)送到查看,整個過程都不需要刷新整個頁面。好了,最后看看效果圖吧!^_^
1.點擊“提交”,開始發(fā)送數(shù)據(jù)
2. 數(shù)據(jù)發(fā)送成功
3. 刷新評論列表
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com