Login | Iscriviti | FAQ
Anonymous

Simple Javascript Chat

+ Rispondi al messaggio

6 messaggi Pagina 1 di 1


Simple Javascript Chat

da Pixel-Wizard » lun mar 04, 2013 6:20 am

Hey togheter

I have a problem. I made the layout for a simple chat, but now I want to make it work. On the following website is my actual stand: simplechat.comxa.com

If i write a message, nobody can see it except me. What have I to do, if I like to make my posts visible, or better, to make everyones posts visible to each other?

And please don't report me bugs, I know there is still a lot to do. I just want the answer to this question!

Thank you!
Pixel-Wizard
Avatar utente

Pixel-Wizard

  • Messaggi: 4
  • Iscritto il: lun gen 21, 2013 7:31 pm

Re: Simple Javascript Chat

da XainPro » lun mar 04, 2013 3:37 pm

when you submit chat msg
save this message into a txt file
and when page load read that file and echo its content simple

Codice: Seleziona tutto

    <?php
    if( !empty($_POST['clear'])){
       $my_file = 'file.txt';
       if(is_file($my_file)){
    unlink($my_file);
       }
    }
    if( !empty($_POST['chat'])){
    $newData = $_POST['chat'];
    $newData .= "<br>";
    $my_file = 'file.txt';
    $handle = fopen($my_file, 'a+') or die('Cannot open file:  '.$my_file);
    $data = fwrite($handle,$newData);
    }
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
       <meta charset="utf-8">
       <title>FlemChat</title>
       <link rel="stylesheet" href="main.css" type="text/css"/>
       <script src="chat.js"></script>
    </head>
    <body>

       <form id="form1" method="post" action="">
             <textarea id="area2" rows="10" name="chat" cols="50" placeholder="Type here..."></textarea>
             <br>
             <input type="submit" id="button" value="Speak">
       </form>
       <form id="form1" method="post" action="">
             <input type="submit" name="clear" id="button" value="Clear">
       </form>
       <hr>
    <h2>Message:</h2>
    <?php

    $my_file = 'file.txt';
    if(is_file($my_file)){
    $handle = fopen($my_file, 'r') or die('Cannot open file:  '.$my_file);
    $data = fread($handle,filesize($my_file));

    echo nl2br($data);
    }
    ?>
    <hr>
    </body>
    </html>



save this code as filename.php
and enjoy !
Avatar utente

XainPro

  • Messaggi: 3933
  • Iscritto il: ven feb 17, 2012 8:10 pm

Re: Simple Javascript Chat

da Pixel-Wizard » lun mar 04, 2013 5:10 pm

First of all, thank you for your reply.

But isn't that possible with pure JavaScript? If not, is it possible to make a Chat with AJAX?
Avatar utente

Pixel-Wizard

  • Messaggi: 4
  • Iscritto il: lun gen 21, 2013 7:31 pm

Re: Simple Javascript Chat

da XainPro » mar mar 05, 2013 11:52 am

you are right its not possible with only javascript but yes it is possible with AJAX :)
Avatar utente

XainPro

  • Messaggi: 3933
  • Iscritto il: ven feb 17, 2012 8:10 pm

Re: Simple Javascript Chat

da muratsal » mar mar 05, 2013 7:05 pm

there is javascript service https://www.firebase.com/
No need server side scripting.
Avatar utente

muratsal

  • Messaggi: 47
  • Iscritto il: mer ott 17, 2012 12:51 pm
--
my map applications http://haritaaraci.com/

Re: Simple Javascript Chat

da XainPro » mer mar 06, 2013 7:00 am

muratsal
is is no chat service and they are providing service infact they are working server side totally unrelated link to this topic.
Avatar utente

XainPro

  • Messaggi: 3933
  • Iscritto il: ven feb 17, 2012 8:10 pm


+ Rispondi al messaggio

Pagina 1 di 1