JavaScript Tutorials Beginner
Simple AJAX Chat
Basics
- we have 2 files - index.html and w.php
- index.html reads the content and sends your message to w.php
- w.php writes the content and prunes it to $maxlines lines
- content stored as text in chat.txt
- this uses 2 http_requests - 1 for checking the content, 1 for sending your message
The setup is as simple as it can be
2 steps
- copy index.html and w.php in a directory of your choice
- create a file called chat.txt with write-rights for php
you could also do like this:
- copy index.html and w.php
- chmod 777 the whole dir
- start the app to create the chat.txt file
- chmod 755 the dir and 777 the chat.txt
Ridiculously Simple - The Source
Feel free to use/modify it for whatever you want. It's just about the idea.
The 20 lines of JavaScript sourcecode you find in here:
And this is the w.php, which also prunes the content:
add this on top to get a minimum-wait time:
$waitsecs = 5; $lastvisit = $_COOKIE["lachatlv"]; setcookie("lachatlv", time()); if ($lastvisit != "") { $diff = time() - $lastvisit; if ($diff < $waitsecs) { die(); }
}
—
JavaScripts Guides: Beginner, Advanced
JavaScripts Tutorials: Beginner, Advanced
[Home] [Templates] [Blog] [Forum] [Directory] JavaScript Tutorials Beginner -
Simple AJAX Chat
|