ajaxLink - Accessing Data Parameters in sucess function

Dear All ,

Below is the ajaxLink code I am using . I am posting car_type and car_id to my controller , after its successful return in “success”=>‘js:function(data){ }’ is there any way I can get car_type and car_id . Thank You


echo (

	CHtml::ajaxLink(

	   'Delete',

	    Yii::app()->createUrl("partMgmt/removecar"),

	    array(

		    "type"=>"POST",

		    "data"=>array(

			    "car_type"=>$myplaces[$i]['car_type'],

			    "car_id"=>$myplaces[$i]['car_code'],

		    ),

		    "success"=>'js:function(data){                                                              


		     }',

	    ),

	    array(

		    "onclick"=>"if (!confirm('Are you sure?\\r\\nYou are going to unregister for this place.')){return}"

	    )

	)

); 

Regards

Yii Fan

To whatever controller you’re posting your data, echo back the car_type and car_id using the CJSON::encode, catch that in your success: function(data) { data.car_type and data.car_id}

Here’s a rough alteration to your code:

        array(


                "type"=>"POST",


                "dataType"=>"json",


                "data"=>array(


                        "car_type"=>$myplaces[$i]['car_type'],


                        "car_id"=>$myplaces[$i]['car_code'],


                ),


                "success"=>'js:function(data){                                                              


                        alert(data.car_type + data.car_id);


                 }',


        ),

Inside your controller:

$data = array(‘car_type’ => $_POST[‘car_type’], ‘car_id’ => $_POST[‘car_id’]);

echo CJSON::encode($data);

Just a rough editing to your code to help you understand as I said. Ofcourse there are ways and depends on how your controller looks like.

Hope this is clear.

Thank You rookie84 and that helped me

Regards

Yii Fan