Newbie: Render Json Of A Model In Controller Action


well I am new to Yii and have a problem: I am sending a ajax POST request (with firstname and lastname parameters) from a Jquery Mobile app to the Yii WorkerController’s actionJSON() function. This function (action) retrieves the worker model with column values of submitted firstname and lastname POST values. So here is the code - The problem in the end is that neither of my onSuccess nor onError methods are called in jquery.

JQuery Mobile -

      $(document).ready(function() {



                var formData = $("#callAjaxForm").serialize();



                    type: "POST",

                    url: "localhost/myYiiVodovod1/index.php?r=site/json",

                    //crossDomain: true,

                    cache: false,

                    data: formData,

		    //dataType   : 'json',

                    success: onSuccess,

                    error: onError



                return false;



Yii workerController - I am not sure whether the findByAttribute() is correct :


public function actionJson(){


              if((isset($_POST['firstName']) && isset($_POST['lastName']))){


                header('Content-type: application/json');  




                echo CJSON::encode($model);  





public function loadModelTwo($fname,$lname){


            $model = Worker::model()->findByAttributes(array('first_name' => $fname, 'last_name' => $lname));



			throw new CHttpException(404,'The requested page does not exist.');



            return $model;