首页 > 解决方案 > PHP 。如何在发布方法后强制我的代码重定向?

问题描述

当我在控制器中执行时mydomaine/sendforward function我得到了预期的重定向THIS_URL

但是使用 Vuejs,当我使用 axios 时,THIS_URL仅在控制台中出现,并且在 POST 方法表单之后不会发生重定向。

我想被重定向到此代码输出中的 URL:

 public function forward(Request $request){
      return view('view', ['data'=>$request]);
 }

查看页面:

<form id="redirectForm" action="<?php echo $_GET['THIS_URL']; ?>" method="post" name="myform">
</form>

问题

标签: phplaravelredirect

解决方案


在您的承诺消费者上,将 设置window.location为您想要的重定向网址,如下所示:

axios.post('your_post_url_here', {data: data})
    .then((response) => {
        //you can do it here
        window.location = "your_redirect_url_here";
    })
    .catch((e) => {
        //OR here
        window.location = "your_redirect_url_here";
    })
    .finally(() => {
        //OR here
        window.location = "your_redirect_url_here";
    });

推荐阅读