Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. class CommentsController extends AppController{
  2. //put your code here
  3. public function add(){
  4. $this->layout = 'user_index';
  5. $this->autoRender = false;
  6. if($this->RequestHandler->isAjax()){
  7. $this->Comment->create();
  8. if($this->Comment->save($this->data)){
  9. $data = $this->Comment->find('first',array(
  10. 'order' => array('Comment.created'=>'desc')
  11. ));
  12. echo "<tr>";
  13. echo "<td>";
  14.  
  15. echo "</td>";
  16. echo "<td>";
  17. echo $data['Comment']['body'];
  18. echo "</td>";
  19. echo "<td>";
  20. echo $data['Comment']['created'];
  21. echo "</td>";
  22. echo "</tr>";
  23.  
  24.  
  25.  
  26. }
  27. }
  28. }
  29.  
  30. $(document).ready(function(){
  31. //postComment
  32. $('#comments').keypress(function(e){
  33. if(e.which === 13){
  34. $('#postComment').submit(function(e){
  35. e.preventDefault();
  36. var formUrl = $(this).attr('action');
  37. var formData = $(this).serialize();
  38. $.ajax({
  39. type: 'POST',
  40. url: formUrl,
  41. data: formData,
  42. success: function(data, statusText, xhr){
  43. $('#myComments').append(data); //<tbody id=myComments>
  44. },
  45. error: function(xhr, statusText,error){
  46. alert(statusText);
  47. },
  48. cache:false
  49. });
  50. return false;
  51. });
  52. }
  53.  
  54. });
  55. //end of savePost
  56. });
  57.  
  58. http://postimg.org/image/eu8xy0i77/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement