<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無重新整理</title> <link href="css/css.css" type="text/css" rel="stylesheet" /> <style type="text/css"> body{color:#555;font-size:14px;padding:0;margin:0;} #form { background:#dedede; padding:10px 20px; width:300px;} #show{ background:#f6f6f6;padding:10px 20px; width:300px;} #show p{ margin:6px; font-size:13px; line-height:22px; border-bottom:1px dashed #cdcdcd;} </style> <script type="text/javascript" src="jquery-1.7.2.min.js"></script> <script type="text/javascript"> $(function(){ $("#sub").click(function(){ //只是說明原理,然後這裡省去了驗證文字框內容的步驟,直接發送ajax請求 $.post("deal.php",{name : $("#name").val(), content : $("#content").val()}, function(data){ if(data.status){ var str = "<p><strong>"+data.name+"</strong> 發表了:"+data.content+"</p>"; $("#show").prepend(str); //在前面追加 }else{ alert("評論失敗"); } }, 'json'); }); }); </script> </head> <body>
<div id="form"> <form action="deal.php" method="get" id="suggest_form"> 使用者名稱:<input type="text" name="name" id="name" /><br/> 內 容:<textarea name="content" id="content"></textarea> <input type="button" value="發布" id="sub" /> </form> </div> <div id="show"> <?php include "config.php"; $sql = "select * from test;"; $res = mysql_query($sql,$link); while($row=mysql_fetch_array($res)){ echo "<p><strong>".$row['name']."</strong> 發表了:".$row['content']."</p>"; } ?> </div> </body> </html> |