Ajax submit not working at all (no reaction on click)

Hi

I am creating an ajax comment element. I have a comment box that when you type in it and hit the submit (in my case comment) button nothing seems to happen, its like there is no code behind the button. I have no idea why this is happening because I am following the instructions of doing an ajax submit that is in the manual: http://book.cakephp.org/view/629/submit

but if i do it with normal submit it works perfectly.

I was hoping someone could tell me what I am doing wrong

here is my code:

comment.php (The element file):


<div class="commentList">
<?php
foreach($comments as $comment){
	echo $comment['Comment']['comment'].'<br/>';
}
?>
</div>

<?php
echo $form->create('Comment');
echo $form->input('Comment.song_id', array('type' => 'hidden', 'value' => $song['Song']['id']));
echo $form->input('Comment.comment');
echo $ajax->submit('Comment', array('url'=> array('controller'=>'comments', 'action'=>'add'), 'update' => 'commentList'));
echo $form->end();
?>

the add function in the comments_controller:


function add(){
		
		if(!empty($this->data)){
			$this->data['Comment']['user_id'] = $this->Session->read('Auth.User.id');
			$this->Comment->save($this->data);
		}
		//find all the comments for the song
		$songComments = $this->Comment->find('all', array('conditions' => array('Comment.song_id' => $this->data['Comment']['song_id'])));
		
		//send the list of comments to the view
		$this->set('comments', $songComments);
	}

Asked by pastryking, on 19/7/10

You write "its like there is no code behind the button" - have you checked the source of your page? Is the code there?

Is a new record being created in the database?

Kryten - on 19/7/10

<< comments | comments >>

0 Answers

Sorry, but there are no answers yet.

Your Answer

You can use Creole Wiki Syntax to format your text.

Tagged with

Rating

0

Viewed

136 times

Last Activity

on 19/7/10