Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Shoutbox w ajaxie
Otto
post
Post #1





Grupa: Zarejestrowani
Postów: 144
Pomógł: 7
Dołączył: 22.03.2010

Ostrzeżenie: (0%)
-----


Nie jestem pewien czy dobry dział ale skoro szukam gotowego rozwiązania to chyba tutaj tongue.gif

Napisałem shoutbox i teraz chcialbym go ulepszyć poprzez dodawanie wiadomości bez odświeżania strony, szukałem troche na forach ale nic nie znalazłem gdyż albo skrypt nie działał poprawnie albo nie umiałem go skonfigurować do swoich potrzeb...
Mógłby ktoś zedytować shoutbox tak aby wiadomości były dodawane bez odświeżania strony?

sb.php
  1. <?php
  2. require("config.php");
  3. ?>
  4. <script type="text/javascript" src="../mintAjax.js"></script>
  5. <script type="text/javascript">
  6. function refresh() {
  7. var req = mint.Request();
  8. req.OnSuccess = function () { document.getElementById("massages").innerHTML = this.responseText;},
  9. req.OnError = function () {document.getElementById("massages").innerHTML = "Wystąpił błąd !!! </br>" + this.responseText + "</br>" + req.xmlHttpRequest.statusText ;}
  10. req.Send ("../sb2.php");
  11. }
  12. var ginter=setInterval(refresh, 1000);
  13. </script>
  14.  
  15. <div id="shoutbox"></div>
  16. <div style="background-color: #fff; width: 320px; padding-left: 10px; padding-top: 11px;">
  17. <form name="sb" action="trans.php" method="post">
  18. <?php
  19. $godzina = date("H:i");
  20.  
  21. if(isset($_SESSION['user_id'])) {
  22. ?>
  23. <input class="inputsb" type="text" name="massage">
  24. <input type="hidden" name="autor" value="<?php echo $user_name; ?>">
  25. <input type="hidden" name="hour" value="<?php echo $godzina; ?>">
  26. <input class="submit" type="submit" name="wyslijsb" value="Wyślij">
  27. </form>
  28. <?php
  29. } else {
  30. echo "<span style='font-size: 13px; color: #39548b'><b>Shoutbox tylko dla zalogowanych!</b></span>";
  31. }
  32. ?>
  33.  


sb2.php
  1. <?php
  2. require("config.php");
  3.  
  4. $sql = "SELECT * FROM shoutbox ORDER BY massage_id DESC LIMIT 20";
  5. $result = mysql_query($sql) or die(mysql_error());
  6.  
  7. while ($row = mysql_fetch_array($result)) {
  8. $id = $row['massage_id'];
  9. $autor = $row['massage_autor'];
  10. $godzina = $row['massage_hour'];
  11. $massage = $row['massage_body'];
  12.  
  13. if (is_int(($id)/2)==TRUE) $bg = "#FFFFFF";
  14. else $bg = "#f0f0f0";
  15.  
  16. ?>
  17. <div style="background-color: <?php echo $bg; ?>; width: 293px; padding: 5px;">
  18. <div style="font-size: 12px; color: #39548b">napisał <b><?php echo $autor; ?></b> o godzinie <?php echo $godzina; ?></div>
  19. <div><?php echo $massage; ?></div>
  20. </div>
  21. <?php
  22. }
  23. ?>


trans.php
  1. <?php
  2. require("config.php");
  3.  
  4. // Shoutbox
  5.  
  6. if(isset($_POST['wyslijsb'])) {
  7. $autor = $_POST['autor'];
  8. $massage = trim($_POST['massage']);
  9. $godzina = $_POST['hour'];
  10.  
  11. if(!empty($massage)) {
  12. $sql = "INSERT INTO shoutbox (massage_autor, massage_body, massage_hour)
  13. VALUES ('$autor', '$massage', '$godzina')";
  14. $result = mysql_query($sql) or die(mysql_error());
  15. header("location:index.php");
  16. } else {
  17. header("location:index.php");
  18. }
  19. }
  20. ...
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 04:00