Page Reloads When I Click Ajaxbutton

[b] <?php

                &#036;form = &#036;this-&gt;beginWidget('CActiveForm', array(

                    'id' =&gt; 'commentsform',

                    'enableAjaxValidation' =&gt; true,


                echo CHtml::ajaxSubmitButton('Save', &#036;this-&gt;createUrl('software/postcomment', array('id' =&gt; 100)), array(

                    'type' =&gt; 'POST',

                    //  'dataType'=&gt;'json',

                    'success' =&gt; 'function(data){






i have the above code written inside a form… but when i click on the submit button the page reloads which shouldnt happen…

please help me


b/c ajax don’t redirect u…

it will just submit the form and will stay on same page

You can do like this if u want to submit form and then redirect to another page

so add below code to ur actionCreate where u save model

echo CJSON::encode(array(

                  	'url' => Yii::app()->createUrl('view', array('id' => $id)),


then inside ajax success function write

window.location.href = data.url;

Have a look at this thread: