Guest User

Untitled

a guest
Jul 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. var lastTime = 0;
  2.  
  3. function waitForMsg2(){
  4. $.getJSON("ajax/new_shoutbox.php", {
  5. time: lastTime
  6. },
  7.  
  8. function(response){
  9.  
  10. $.each(response, function(i,item){
  11.  
  12. var string = '<div class="post" style="border-bottom: 1px solid #ebeff1; text-align: left; position: relative;" id="list-'+item.id+'">'
  13. + '<span class="PostTime" style="display: none">'+ item.date +'</span>'
  14. + '<span style="float: right; font-size: 10px; color: #999999;">'+ item.date_posted +'</span>'
  15. + '<span style="float: left; padding-right: 2px; font-weight: 600; '+ item.nick_color +'">'+item.nick_name+':</span>'
  16. + '<div style="clear: both;">'+item.message+'</span>'
  17. +'</div>';
  18.  
  19. $('#shoutcontent').append(string);
  20. $('#list-'+item.id).fadeIn('slow');
  21.  
  22. });
  23.  
  24. lastTime = $('#shoutcontent .post:first .PostTime').text();
  25. timeoutID = setTimeout(waitForMsg2, 10000);
  26. })
  27.  
  28.  
  29. };
  30.  
  31. $(document).ready(function(){
  32. waitForMsg();
  33. waitForMsg2();
  34.  
  35. $('#form textarea').bind('keydown', function(e) {
  36. if (e.keyCode == 13 && !e.shiftKey) {
  37.  
  38. if ($('#form textarea').val().length > 0) {
  39.  
  40. $.ajax({
  41. type: "POST",
  42. url: "ajax/sendshout.php",
  43. data: "message=" + $('#message').val(),
  44.  
  45. complete: function(data){
  46. waitForMsg2();
  47. }
  48.  
  49. });
  50.  
  51. e.preventDefault();
  52. $('#form textarea').val('');
  53.  
  54. }else {
  55. alert("Please enter a message!!");
  56. }
  57.  
  58. }
  59.  
  60. });
  61.  
  62. });
Add Comment
Please, Sign In to add comment