Witam!

Mam problem z dodaniem odświeżania do shoutboxa. Wszystko działa dobrze skrypt pobiera dane i je wyświetla. Gdy dodamy posta, po dodaniu wywoływana jest fukcja updateShoutbox();, pobiera dane i wyswietla. Chciałem dodać przycisk [Odśwież] wywoływałem to tak:

  1. <a href="#odswiezWpisy" id="odswiez">[Odśwież]</a>




[JAVASCRIPT] pobierz, plaintext
  1. $(document).ready(function() {
  2.  
  3.  $('#odswiez').click(function() {
  4.  
  5.  updateShoutbox();
  6.  
  7. });
  8.  
  9. });
  10.  
[JAVASCRIPT] pobierz, plaintext


a tutaj kod PHP i Javascript, oraz index.html (znajduja sie w jednym katalogu shoutbox i index.html jest includowany do pliku php top.php a ten do plikow takich jak index.php, galeria.php):

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
  3.  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4.  <link rel="stylesheet" href="../styl/s6.css" type="text/css" media="screen" />
  5.   <script type="text/javascript" src="main.js"></script> 
  6. <script type="text/javascript" src="../js/shoutbox.js"></script>
  7. </head>
  8. <div class="shoutbox_main">
  9. <div id="panel_shoutbox">
  10. <div id="shoutbox" style="display: none;">
  11.  <form method="post" id="form">
  12.   <table>
  13.   <tr>
  14.   <td><label>Nick</label></td>
  15.   <td><input class="text user" id="nick" type="text" MAXLENGTH="15" /></td>
  16.   </tr>
  17.   <tr>
  18.   <td><label>Treść</label></td>
  19.   <td><input class="text" id="message" type="text" MAXLENGTH="255" /></td>
  20.   </tr>
  21.   <tr>
  22.   <td></td>
  23.   <td><input id="send" type="submit" value="Wyraz To!" /> </td>
  24.   </tr>
  25.   </table>
  26.  </form>
  27.  
  28.  <div id="container">
  29.   <span class="clear"></span>
  30.   <div class="content">
  31.   <h1>Ostatnie posty:</h1>
  32.   <div id="loading">:)</div>
  33.  
  34. <a href="#odswiezWpisy" id="odswiez">[Odśwież]</a>
  35.   <ul>
  36.   </ul>
  37.   </div>
  38.  </div><div id="shoutbox_napis"><img src="../shoutbox/shoutbox.png" /></div>
  39. </div>
  40. <div class="tab">
  41. <div class="top">
  42.  <div id="shoutbox_toggle">
  43.   <a href="#shoutbox_otworz" id="sh_open" class="open"></a>
  44.   <a href="#shoutbox_zamknij" id="sh_close" style="display: none;" class="close"></a>
  45.  </div>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50.  
  51. </body>
  52. </html>
  53.  



[JAVASCRIPT] pobierz, plaintext
  1. $(document).ready(function(){
  2.  
  3.  var inputUser = $("#nick");
  4.  var inputMessage = $("#message");
  5.  var loading = $("#loading");
  6.  var messageList = $(".content > ul");
  7.  
  8.  
  9.  function updateShoutbox(){
  10.  
  11.   messageList.hide();
  12.   loading.fadeIn();
  13.  
  14.   $.ajax({
  15.   type: "POST", url: "shoutbox.php", cache: false, data: "action=update",
  16.   complete: function(data){
  17.   loading.fadeOut();
  18.   messageList.html(data.responseText);
  19.   messageList.fadeIn(2000);
  20.   }
  21.   });
  22.  }
  23.  
  24.  
  25.  function checkForm(){
  26.   if(inputUser.attr("value") && inputMessage.attr("value"))
  27.   return true;
  28.   else
  29.   return false;
  30.  }
  31.  
  32.  updateShoutbox();
  33.  
  34.  $("#form").submit(function(){
  35.   if(checkForm()){
  36.   var nick = inputUser.attr("value");
  37.   var message = inputMessage.attr("value");
  38.  
  39.   $("#send").attr({ disabled:true, value:"Wysylanie..." });
  40.   $("#send").blur();
  41.  
  42.   $.ajax({
  43.   type: "POST", url: "shoutbox.php", cache: false, data: "action=insert&nick=" + nick + "&message=" + message,
  44.   complete: function(data){
  45.   messageList.html(data.responseText);
  46.   updateShoutbox();
  47.  
  48.  
  49.   $("#send").attr({ disabled:false, value:"Wyraz To!" });
  50.   }
  51.   });
  52.   }
  53.   else alert("Wypelnij wszystkie pola!");
  54.  
  55.   return false;
  56.  });
  57. });
  58.  
  59. $(document).ready(function() {
  60.  
  61.  $('#odswiez').click(function() {
  62.  
  63.  updateShoutbox();
  64.  
  65. });
  66.  
  67. });
  68.  
  69.  
[JAVASCRIPT] pobierz, plaintext
  1. <?php
  2.  
  3. require_once "../engine.php";
  4.  
  5. if(!$_POST['action']){
  6.  header ("Location: index.php"); 
  7. } else {
  8.  switch($_POST['action']){
  9.   case "update":
  10.   $res = dbquery("SELECT date, user, message FROM shoutbox ORDER BY date DESC LIMIT 10");
  11.   while($row = mysql_fetch_array($res)){
  12.   $result .= "<div class='contentin'><span class='shoutbox_nick'><b>".$row['user']." </b></span> <span class=\"date\"> ".$row['date']."</span><br /><span class=\"message\">".$row['message']."</span> </div>";
  13.   }
  14.   echo $result."<script type=\"text/javascript\">
  15.  $(document).ready(function(){
  16. $('div.contentin:even').css('background', '#780000');
  17. });
  18. </script>";
  19.   break;
  20.   case "insert":
  21.   $user = mysql_real_escape_string(strip_tags($_POST['nick']));
  22.   $message = mysql_real_escape_string(strip_tags($_POST['message']));
  23.   echo dbquery("INSERT INTO shoutbox(user, message) VALUES('$user', '$message')");
  24.   break;
  25.  }
  26. }
  27.  
  28. ?>




ale po kliknieciu nic sie nie dzieje





na wstępie mówie że chciałem edytować post @up, ale się rozwaliło kodowanie więc piszę pod nim.

Sam rozwiązałem problem smile.gif

[JAVASCRIPT] pobierz, plaintext
  1. $(document).ready(function() {
  2.  
  3.  $('#odswiez').click(function() {
  4.  var loading = $("#loading");
  5.  var messageList = $(".content > ul");
  6.  
  7.   //just for the fade effect
  8.   messageList.hide();
  9.   loading.fadeIn();
  10.   //send the post to shoutbox.php
  11.   $.ajax({
  12.   type: "POST", url: "shoutbox.php", data: "action=update",
  13.   complete: function(data){
  14.   loading.fadeOut();
  15.   messageList.html(data.responseText);
  16.   messageList.fadeIn(2000);
  17.   }
  18.   });
  19.  });
  20. });
[JAVASCRIPT] pobierz, plaintext


co mnie zdziwiło pomogło ponowne napisanie tego samego(jest 2 razy w dokumencie) z taką różnicą że bez
[JAVASCRIPT] pobierz, plaintext
  1. function updateShoutbox(){
  2.  
  3. ....
  4.  
  5. }
[JAVASCRIPT] pobierz, plaintext


i bez wywoływania jej
[JAVASCRIPT] pobierz, plaintext
  1. updateShputbox();
[JAVASCRIPT] pobierz, plaintext