$This->Render Does Not Render

hey,

I have an action in my controller which performs $this->render when i change a value in a Dropdownlist. This is done by AJAX and JQUERY. Unfortunately the only thing that happens is that in the POST response there is the whole page that should be rendered. But the page itself does not update. Why is that?

In my view:


Yii::app()->clientScript->registerScript('show', "

        $('#cat0_name').change(function()

		{

                loadData();

        });


        function loadData()

		{

                $.ajax(

				{

                        type: 'POST',

                        url: '".CController::createUrl('loadCategories')."',

                        data:

                        {

                              cat: $('#cat0_name').val()

                        },

                        success:

                                function (data)

								{

                                        $('#test').html(data);

                                }

                });


        }

");

In my Controller:


    public function actionLoadCategories()

    {

        if(isset($_POST['cat']))

        {

            $cat = $_POST['cat'];

            $this->actionIndex(array('category'=>$cat));

        }

    }

and


	public function actionIndex($array=null)

	{

        $criteria=new CDbCriteria();

        if($array)

        {

            foreach($array AS $key => $value)

            {

                $criteria->compare($key,$value);

            }

         }


        $dataProvider=new CActiveDataProvider('Objects',array(

            'criteria'=>$criteria,

            'pagination'=>array(

                'pageSize'=>20,

            )));


        if(Yii::app()->request->isAjaxRequest)

        {

            $this->renderPartial('index',array(

                'conditions' => $array, 'dataProvider'=>$dataProvider),false,true);

        }

        else

        {

            $this->render('index',array(

                'conditions' => $array, 'dataProvider'=>$dataProvider));

        }

	}

So in conclusion: I click on an entry in the dropdown, I see nothing but when I look at the Post response via firebug I see that the whole page that should be rendered is the response of the request.

I see that you are updating a dom element with the id ‘test’




...

$('#test').html(data);

...



Check if this element is really defined (i.e. <div id=’#test’>)

How can I update the whole page instead of a dom Element?

I don’t get why executing the render method does not rerender the page itself …

Really nobody? :(

I don’t need the success thing, do I? Because via


url: '".CController::createUrl('loadCategories')."'

I tell the application what to do. In the action it says what to render or not?

I have the same problem.

I have a modal window which i am doing certain action (insert, update …) and i want to have a button that render to another view.

First try:


echo CJSON::encode(array('status'=>'200', 'redirect'=>  Yii::app()->createAbsoluteUrl('products/view')));

and have in your button


    .....

          'url'=>CController::createUrl('/product/insert'),

          'ajaxOptions'=>array(.....

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

                    {

                      if(data.status == 200)

                      {

                         redirect=data.redirect;

                         window.location.href=redirect;

                      } else {

                                some error message

                             }

                    }')

the above change the url but the view is not rendered.

Second try:

No success on the button

but in the controller action of insert i have


$this->render('view',array('model'=>$model,));

the above generate the html code (saw it in firebug) but didn’t change the url of the browser.

So obviously i do something really wrong if anyone can help i would appreciate.