gpt4 book ai didi

php - ajax提交按钮 : controller action not redirecting in Yii

转载 作者:行者123 更新时间:2023-12-01 10:14:50 25 4
gpt4 key购买 nike

我正在使用 ajaxSubmitButton 将数据发布到我的 Controller 。该 Controller 操作然后在事务中生成两个插入语句。所有这些都工作得很好。我现在想要的是一旦交易完成就被重定向到一个新 View ,但我无法让它工作。

当我点击我的按钮时,交易已处理,但我仍停留在同一页面上。我也尝试过在按钮中使用“更新”并包装页面的一部分,但没有内容更新。这并不是我最终想要的,因为我想最终呈现一个全新的 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;
}
}

最佳答案

重定向无效,因为您使用了 ajax。

试试这段代码:

echo CHtml::ajaxSubmitButton('submit',          
array('/player/mark'),
array(
'type'=>'POST',
'data' => array(...),
'success' => 'js:function(){window.location="your_url"}',
));

将 *your_url* 替换为您要重定向到的 url

关于php - ajax提交按钮 : controller action not redirecting in Yii,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9324078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com