Yii Framework Forum: $This->Render Does Not Render - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

$This->Render Does Not Render Rate Topic: -----

#1 User is offline   Schnodderbalken 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 05-February 13

Posted 13 February 2013 - 04:56 AM

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.
0

#2 User is offline   guaruja 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 10-March 12

Posted 13 February 2013 - 06:17 AM

View PostSchnodderbalken, on 13 February 2013 - 04:56 AM, said:

But the page itself does not update. Why is that?


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

#3 User is offline   Schnodderbalken 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 05-February 13

Posted 13 February 2013 - 11:57 AM

View Postguaruja, on 13 February 2013 - 06:17 AM, said:

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?
0

#4 User is offline   Schnodderbalken 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 05-February 13

Posted 13 February 2013 - 07:15 PM

I don't get why executing the render method does not rerender the page itself ..
0

#5 User is offline   Schnodderbalken 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 05-February 13

Posted 15 February 2013 - 10:55 AM

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?
0

#6 User is offline   jimsam 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 04-September 13

Posted 04 September 2013 - 07:57 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users