AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein [XHTML] Ajax-Chat in Seite einbinden
Thema durchsuchen
Ansicht
Themen-Optionen

[XHTML] Ajax-Chat in Seite einbinden

Ein Thema von Saul · begonnen am 10. Jan 2009 · letzter Beitrag vom 11. Jan 2009
Antwort Antwort
Saul
(Gast)

n/a Beiträge
 
#1

Re: [XHTML] Ajax-Chat in Seite einbinden

  Alt 10. Jan 2009, 14:39
Also ich verstehe auch noch nicht ganz, wie das funktioniert, aber es funktioniert auf jeden Fall ^^
(siehe den Test, den ich oben schon gepostet habe) Alles schon mit nem Kumpel getestet. Wir haben beide die Nachrichten vom anderen bekommen.
Hier sonst mal der komplette Code
Code:
<?echo '<?xml version="1.0" encoding="ISO-8859-1"?>' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<?php
        require("Sajax.php");

        function colorify_ip($ip)
        {
                $parts = explode(".", $ip);
                $color = sprintf("%02s", dechex($parts[1])) .
                                 sprintf("%02s", dechex($parts[2])) .
                                 sprintf("%02s", dechex($parts[3]));
                return $color;
        }

        function add_line($msg) {
                $f = fopen("/tmp/wall.html", "a");
                $dt = date("Y-m-d h:i:s");
                $msg = strip_tags(stripslashes($msg));
                $remote = $_SERVER["REMOTE_ADDR"];
                // generate unique-ish color for IP
                $color = colorify_ip($remote);
                fwrite($f, "<span style=\"color:#$color\">$dt</span> $msg
\n");
                fclose($f);
        }

        function refresh() {
                $lines = file("/tmp/wall.html");
                // return the last 25 lines
                return join("\n", array_slice($lines, -25));
        }

        $sajax_request_type = "GET";
        sajax_init();
        sajax_export("add_line", "refresh");
        sajax_handle_client_request();
?>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<head>
      <link href="style.css" rel="stylesheet" type="text/css" />

      <script type="text/javascript">
        //<![CDATA[
        <?
        sajax_show_javascript();
        ?>

        var check_n = 0;
        var old_data = "--";

        function refresh_cb(new_data) {
                if (new_data != old_data) {
                        document.getElementById("wall").innerHTML = new_data;
                        setTimeout("refresh()", 1000);
                        old_data = new_data;
                } else {
                        setTimeout("refresh()", 2500);
                }
                document.getElementById("status").innerHTML = "Checked #" + check_n++;
        }

        function refresh() {
                document.getElementById("status").innerHTML = "Checking..";
                x_refresh(refresh_cb);
        }

        function add_cb() {
                // we don't care..
        }

        function add() {
                var line;
                var handle;
                handle = document.getElementById("handle").value;
                line = document.getElementById("line").value;
                if (line == "")
                        return;
                sajax_request_type = "POST";
                x_add_line("[" + handle + "] " + line, add_cb);
                document.getElementById("line").value = "";
        }
        //]]>
        </script>

</head>
<body onload="refresh();">
<div id="container">
      <div id="kopf"></div>
      <div id="navigation"><div id="rollovermenu"><?php include 'navi.ink' ?></div></div>
      <div id="links"><?php include 'valid.ink' ?></div>

      <div id="inhalt">
           <h1>Chat</h1>

           <form action="#" onsubmit="add();return false;">
                 <input type="text" name="handle" id="handle" value="(Name)" onfocus="this.select()" style="width:130px;" />
                 <input type="text" name="line" id="line" value="(Nachricht)" onfocus="this.select()" style="width:300px;" />
                 <input type="button" name="check" value="Senden" onclick="add(); return false;" />
                 <div id="wall"></div>
                 <div id="status">[i]Loading..[/i]</div>
           </form>
      </div>
</div>
</body>
</html>
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:35 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz