문제

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

도움이 되었습니까?

해결책 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));
  }

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top