Question

How can i redirect to another controller action view using yii ajax call ? here is my ajax function

function test(id) 
{  
    $.ajax({
       type: "POST",      
       data: "id="+id,
       url: "<?php echo Yii::app()->createUrl('controller/action'); ?>",
       success: function (msg){ }   
    });  
}

From my action i want to call a view in another window.

  public function action
  {
     //doing some php code here to create $dataProvider
     $this->render('view',array('dataProvider'=>$dataProvider),array('target'=>'_blank'));
  }

is this possible ? please help

Was it helpful?

Solution 2

At last I got the answer for my question..

I'm using CHtml::link instead of using ajax.

view :

CHtml::link(
        CHtml::encode('id'), 
        array('controller/action','id'=>'id'),
        array('href'=>'/index.php/controller/action',
        'target'=>'_blank')
     )

Controller :

public function action
  {
     //doing some php code here to create $dataProvider  
     $this->render('view',array('dataProvider'=>$dataProvider));
  }

OTHER TIPS

You'll need to do the redirect in Javascript, for example in the success function. You can pass the URL as output from the PHP-action, then pick that up and set window.location.href.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top