Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. <div id="chat"></div><br />
  2. <form action="#" method="post">
  3. <input type="hidden" id="nome" value="<?=$usuario?>" size="6">
  4. <input type="text" id="mensagem" width="80%" >
  5. <button type="button" id="enviar" title="enviar" >Enter</button>
  6. </form>
  7.  
  8. <?php
  9. $nome = $_POST['nome'];
  10. $mensagem = $_POST['mensagem'];
  11. $linha = $nome.' - '.$mensagem.'<br>';
  12. $arquivo = file('chatlog.htm');
  13. array_unshift($arquivo, $linha);
  14. file_put_contents('chatlog.htm', $arquivo);
  15. ?>
  16.  
  17. $(function() {
  18. conversar();
  19. $('#enviar').click(function() {
  20. var nome = $('#nome').val();
  21. var mensagem = $('#mensagem').val();
  22. $.post('chat.php', {'nome':nome, 'mensagem': mensagem }, function() {
  23. conversar;
  24. $('#mensagem').val('');
  25. });
  26. });
  27.  
  28. function conversar() {
  29. $('#chat').load('chatlog.htm');
  30. $('#mensagem').focus();
  31. }
  32. setInterval(conversar, 3000);
  33. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement