Json Not Working In Ajaxsubmit Button

i have the following code in controller

[b]public function actionTest($id)

    {


        $test=array(1,2,3);


        print_r($test);


       


    }[/b]

in index.php

[b]<?php

$form = $this->beginWidget(‘CActiveForm’, array(

'id' =&gt; 'job-form',


'enableAjaxValidation' =&gt; true,


    ));

echo CHtml::ajaxSubmitButton(‘Save’, $this->createUrl(‘site/test’, array(‘id’ => 12)), array(

'type' =&gt; 'POST',

‘dataType’ => ‘json’,

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


  alert(data);

}’,

));

$this->endWidget();

?>

[/b]

but i can’t get the alert to work and the array is not getting displayed…

if i comment the datatype it works fine…

In the controller add this and check




public function actionTest($id)

{

//$test=array(1,2,3);

//print_r($test);


 echo CJSON::encode(array(

                                  'status'=>'success'));

                            Yii::app()->end();

}



You can check the return in index.php like this




echo CHtml::ajaxSubmitButton('Save', $this->createUrl('site/test', array('id' => 12)), array(

'type' => 'POST',

'dataType' => 'json',

'success' => 'function(data){

if(data.status=="success")

       {

         alert("Your Message");

       }

alert(data);

}',

));



thanks a lot for the rep… it worked…

Hey Guys,

I have another question. i want to add feedback to my site. I put the following codes in my post controller:

public function actionPutFB(&#036;id)


{


	&#036;p=&#036;this-&gt;loadModel();


	&#036;f = new Feedback();


	


	&#036;f-&gt;author_id = Yii::app()-&gt;user-&gt;id;


	&#036;f-&gt;post_id = &#036;p-&gt;id;





	try { 


		 if (&#036;f-&gt;save()) {


		 	&#036;p = Post::model()-&gt;findByPk( &#036;f-&gt;post_id );


		 	&#036;p -&gt; sumFeedback();


			echo CJSON::encode(array('status'=&gt;'success'));


		 }

// else echo json_encode($sr=false);

	} catch (Exception &#036;e) {


		 throw new CHttpException(400,'sara');


	}


}

and the following in appropriate view:

<div id="feedback">

<?php

echo CHtml::ajaxLink(‘UnLike’ ,

		&#036;this-&gt;createUrl('post/PutFB'),


		array(


			'type'=&gt;'POST',


			'dataType'=&gt; 'json',


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


                                {


									if(data.status==&quot;success&quot;){


									&#036;(&quot;#feedback&quot;).val(parseInt(&#036;(&quot;#feedback&quot;).val() , 10)+1);


										}


                                }',

));

echo $model->feedback;

?>

</div>

but when press like link nothings happened. could you help me?