Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. include 'sseFile.php';
  2. /**
  3. * Comment creation end point
  4. */
  5. function createComment(){
  6. $submittedComment = $_POST["comment"];
  7.  
  8. $comment = new comment();
  9. $comment->setComment($submittedComment);
  10.  
  11. $comment->create();
  12.  
  13. sendMsg(); //the SSE fucntion in the other file.
  14. }
  15.  
  16.  
  17.  
  18. header('Content-Type: text/event-stream');
  19. header('Cache-Control: no-cache');
  20.  
  21.  
  22.  
  23.  
  24. /**
  25. * Server side code for SSE.
  26. * This returns the most recent comment to the front end.
  27. */
  28. function sendMsg(){
  29. $comment = new comment();
  30. $comment->getLatestComment();
  31.  
  32. echo "data: {"msg": "".addcslashes($comment->getComment()."""} nn";
  33. ob_flush();
  34. flush();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement