Newbie: Render Json Of A Model In Controller Action

Hello,

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() {

            $("#submit").click(function(){

  

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

  

                $.ajax({

                    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');  

                

                $model=$this->loadModelTwo($_POST['firstName'],$_POST['lastName']);

                

                echo CJSON::encode($model);  


            }

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

                    

        }


public function loadModelTwo($fname,$lname){

               

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

                      

            if($model===null){

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

            }              

                   

            return $model;

            

        }



Thanks.