
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
<?php require("config.php"); ?> <script type="text/javascript" src="../mintAjax.js"></script> <script type="text/javascript"> function refresh() { var req = mint.Request(); req.OnSuccess = function () { document.getElementById("massages").innerHTML = this.responseText;}, req.OnError = function () {document.getElementById("massages").innerHTML = "Wystąpił błąd !!! </br>" + this.responseText + "</br>" + req.xmlHttpRequest.statusText ;} req.Send ("../sb2.php"); } var ginter=setInterval(refresh, 1000); </script> <div id="shoutbox"></div> <div style="background-color: #fff; width: 320px; padding-left: 10px; padding-top: 11px;"> <form name="sb" action="trans.php" method="post"> <?php ?> <input class="inputsb" type="text" name="massage"> <input class="submit" type="submit" name="wyslijsb" value="Wyślij"> </form> <?php } else { echo "<span style='font-size: 13px; color: #39548b'><b>Shoutbox tylko dla zalogowanych!</b></span>"; } ?>
sb2.php
<?php require("config.php"); $sql = "SELECT * FROM shoutbox ORDER BY massage_id DESC LIMIT 20"; $id = $row['massage_id']; $autor = $row['massage_autor']; $godzina = $row['massage_hour']; $massage = $row['massage_body']; else $bg = "#f0f0f0"; ?> </div> <?php } ?>
trans.php
<?php require("config.php"); // Shoutbox $autor = $_POST['autor']; $godzina = $_POST['hour']; $sql = "INSERT INTO shoutbox (massage_autor, massage_body, massage_hour) VALUES ('$autor', '$massage', '$godzina')"; } else { } } ...