I am using ajaxSubmitButton to POST data to my controller. That controller action then makes two insert statements in a transaction. All that is working just fine. What I want now is once the transaction is complete to be redirected to a new view but I can’t get that to work.
When I click my button the transaction is processed but I remain on the same page. I have also tried using ‘update’ within the button and wrapping part of the page but none of the content updates. That is not ultimately what I am after though since I want to end up rendering a whole new view.
Here is what I have…
VIEW
echo CHtml::ajaxSubmitButton('submit',
array('/player/mark'),
array(
'type'=>'POST',
'data' => array(...),
));
CONTROLLER
public function actionMark()
{
$connection = yii::app()->db;
$transaction=$connection->beginTransaction();
try
{
$connection = yii::app()->db;
$sql1 = "INSERT ...";
$command=$connection->createCommand($sql1);
...
$command->execute();
$connection = yii::app()->db;
$sql2 = "INSERT ...";
$command=$connection->createCommand($sql2);
...
$command->execute();
$transaction->commit();
$this->redirect(array('manage')); // THIS IS NOT WORKING
}
catch(Exception $e)
{
$transaction->rollBack();
$this->refresh;
}
}
Redirect not working because you using ajax.
Try this code:
Replace *your_url* to url you want redirect to