当前位置: 代码迷 >> Web前端 >> shutbox jquery无刷新公布评论
  详细解决方案

shutbox jquery无刷新公布评论

热度:741   发布时间:2013-12-29 13:07:03.0
shutbox jquery无刷新发布评论

shutbox jquery无刷新发布评论

?本例的数据库很简单,一看就会明白

shutbox jquery无刷新发布评论
演示

?

?

XML/HTML Code
  1. <form?method="post"?id="form">??
  2. ????????<table?cellpadding="0"?cellspacing="0">??
  3. ????????????<tr>??
  4. ????????????????<td><label>User</label></td>??
  5. ????????????????<td><input?class="text?user"?id="nick"?type="text"?MAXLENGTH="25"?/></td>??
  6. ????????????</tr>??
  7. ????????????<tr>??
  8. ????????????????<td><label>Message</label></td>??
  9. ????????????????<td><input?class="text"?id="message"?type="text"?MAXLENGTH="255"?/></td>??
  10. ????????????</tr>??
  11. ????????????<tr>??
  12. ????????????????<td></td>??
  13. ????????????????<td><input?id="send"?type="submit"?value="Shout?it!"?/></td>??
  14. ????????????</tr>??
  15. ????????</table>??
  16. ????</form>??
  17. ????<div?id="container">??
  18. ????????<ul?class="menu">??
  19. ????????????<li>Shoutbox</li>??
  20. ????????</ul>??
  21. ????????<span?class="clear"></span>??
  22. ????????<div?class="content">??
  23. ????????????<h1>Latest?Messages</h1>??
  24. ????????????<div?id="loading"><img?src="css/images/loading.gif"?alt="Loading..."?/></div>??
  25. ????????????<ul>??
  26. ????????????<ul>??
  27. ????????</div>??
  28. ????</div>??

shoutbox.php

?

PHP Code
  1. <?php??
  2. ??
  3. /************************?
  4. ????CONSTANTS?
  5. /************************/??
  6. define("HOST",?"localhost");??
  7. define("USER",?"root");??
  8. define("PASSWORD",?"");??
  9. define("DB",?"");??
  10. ??
  11. /************************?
  12. ????FUNCTIONS?
  13. /************************/??
  14. function?connect($db,?$user,?$password){??
  15. ????$link?=?@mysql_connect($db,?$user,?$password);??
  16. ????mysql_query("set?names?utf8;");??
  17. ????if?(!$link)??
  18. ????????die("Could?not?connect:?".mysql_error());??
  19. ????else{??
  20. ????????$db?=?mysql_select_db(DB);??
  21. ??????????
  22. ????????if(!$db)??
  23. ????????????die("Could?not?select?database:?".mysql_error());??
  24. ????????else?return?$link;??
  25. ????}??
  26. }??
  27. function?getContent($link,?$num){??
  28. ????$res?=?@mysql_query("SELECT?*?FROM?content?ORDER?BY?updatetime?DESC?LIMIT?".$num,?$link);??
  29. ????if(!$res)??
  30. ????????die("Error:?".mysql_error());??
  31. ????else??
  32. ????????return?$res;??
  33. }??
  34. function?insertMessage($user,?$message){??
  35. ????$updatetime=date("Y-m-d?H:i:s",time());??
  36. ????$query?=?sprintf("INSERT?INTO?content?(name,?message,updatetime)?VALUES('%s',?'%s','$updatetime');",?mysql_real_escape_string(strip_tags($user)),?mysql_real_escape_string(strip_tags($message)));??
  37. ????$res?=?@mysql_query($query);??
  38. ????if(!$res)??
  39. ????????die("Error:?".mysql_error());??
  40. ????else??
  41. ????????return?$res;??
  42. }??
  43. ??
  44. /******************************?
  45. ????MANAGE?REQUESTS?
  46. /******************************/??
  47. if(!$_POST['action']){??
  48. ????//We?are?redirecting?people?to?our?shoutbox?page?if?they?try?to?enter?in?our?shoutbox.php??
  49. ????header?("Location:?index.html");???
  50. }??
  51. else{??
  52. ????$link?=?connect(HOST,?USER,?PASSWORD);??
  53. ????switch($_POST['action']){??
  54. ????????case?"update":??
  55. ????????????$res?=?getContent($link,?20);??
  56. ????????????while($row?=?mysql_fetch_array($res)){??
  57. ????????????????$result?.=?"<li><strong>".$row['name']."</strong><img?src=\"css/images/bullet.gif\"?alt=\"-\"?/>".$row['message']."?<span?class=\"date\">".$row['updatetime']."</span></li>";??
  58. ????????????}??
  59. ????????????echo?$result;??
  60. ????????????break;??
  61. ????????case?"insert":??
  62. ??????????????
  63. ????????????echo?insertMessage($_POST['nick'],?$_POST['message']);??
  64. ????????????break;??
  65. ????}??
  66. ????mysql_close($link);??
  67. }??
  68. ??
  69. ??
  70. ?>??
?


原文地址:http://www.freejs.net/article_biaodan_125.html

  相关解决方案