您可以使用javascript重定向页面。
在控制器中,返回如下响应:
use yii\helpers\Url;
public function actionSaveChanges()
{
$post = \Yii::$app->request->post();
$this->Posts->updateFields($post['request_id'], $post);
return $this->asJson([
'url' => Url::to('/posts')
]);
}
在js中,按如下方式更改代码:
requestSend: function(e){
let data = {
request_id: e.target.dataset.request_id
};
$.ajax(
{
url: '/posts/save-changes',
method: 'post',
dataType: 'html',
data: data,
success: function(result)
{
window.location.href = result.url
},
error: function()
{
console.log('error');
}
});
},