Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CommentsController extends AppController{
- //put your code here
- public function add(){
- $this->layout = 'user_index';
- $this->autoRender = false;
- if($this->RequestHandler->isAjax()){
- $this->Comment->create();
- if($this->Comment->save($this->data)){
- $data = $this->Comment->find('first',array(
- 'order' => array('Comment.created'=>'desc')
- ));
- echo "<tr>";
- echo "<td>";
- echo "</td>";
- echo "<td>";
- echo $data['Comment']['body'];
- echo "</td>";
- echo "<td>";
- echo $data['Comment']['created'];
- echo "</td>";
- echo "</tr>";
- }
- }
- }
- $(document).ready(function(){
- //postComment
- $('#comments').keypress(function(e){
- if(e.which === 13){
- $('#postComment').submit(function(e){
- e.preventDefault();
- var formUrl = $(this).attr('action');
- var formData = $(this).serialize();
- $.ajax({
- type: 'POST',
- url: formUrl,
- data: formData,
- success: function(data, statusText, xhr){
- $('#myComments').append(data); //<tbody id=myComments>
- },
- error: function(xhr, statusText,error){
- alert(statusText);
- },
- cache:false
- });
- return false;
- });
- }
- });
- //end of savePost
- });
- http://postimg.org/image/eu8xy0i77/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement