Ajax SubmitButton Yii不使用url选项

时间:2014-02-03 18:08:05

标签: ajax yii

我在ajaxSubmitButton视图调用的名为_form的视图中写了viewcomment

当浏览器在按钮上显示视图_form和鼠标时,我可以看到链接为post/viewComment而不是post/newComment1,如我的代码所示

<div class="row buttons2">
    <?php echo "toto"; ?>
    <?php echo CHtml::ajaxSubmitButton(
                    'AjaxSave',
                    Yii::app()->createUrl('post/newComment1'),
                    array(
                        'type' => 'POST',
                        'dataType'=>'json',
                        'success'=>'js:function(data){
                            alert("commentSubmitted");}',
                        'error'=>'js:function(data){
                            alert("comment NOT Submitted");}',  
                        )
        ); 
        ?>
    </div>

我的操作newComment1包含以下内容

public function newComment1($post)
    {
        $comment=new Comment;
        if(isset($_POST['ajax']) && $_POST['ajax']==='comment-form')
        {

            Yii::app()->end();
        }
        if(isset($_POST['Comment']))
        {
            $comment->attributes=$_POST['Comment'];
            if($post->addComment($comment))
            {
                if($comment->status==Comment::STATUS_PENDING)
                    Yii::app()->user->setFlash('commentSubmitted','Thank you for your comment. Your comment will be posted once it is approved.');
                   $this->refresh();
            }
        }
        return $comment;
    }

我不明白为什么?

提前感谢您的帮助

0 个答案:

没有答案