php - How can i redirect to another controller action view using yii call?

969

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

385

Answer

Solution:

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.

206

Answer

Solution:

At last I got the answer for my question..

I'm usingCHtml::link instead of usingajax.

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

People are also looking for solutions to the problem: javascript - jQuery countdown - apply to new elements loaded via AJAX / PHP

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.