php - PHP 。如何在发布方法后强制我的代码重定向?
问题描述
当我在控制器中执行时mydomaine/send
,forward 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>
问题
解决方案
在您的承诺消费者上,将 设置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";
});
推荐阅读
- powershell - 从文件夹中删除用户权限
- javascript - 有没有人在不使用 SharePoint 框架的情况下将 React 或 TypeScript 或两者与 SharePoint 一起使用?
- sql - Presto:发布时区更改为正确区域的表
- c# - 如何判断 SqliteConnection 是否创建了数据库?
- excel - 上一张表中的 VLOOKUP
- php - 使用表时访问刀片中的对象属性
- azure - 使用共享访问签名从 Azure Blob 服务访问 Blob 时是否可以定义自定义错误?
- c# - IoT Edge 模块上的计时器
- java - 如何使用 Eclipse 将 Maven 项目导出到 exe(或 jar)文件?
- javascript - 文本输入 - 限制不超过 5 位小数和超过 100 位