Javascript Laravel从视图重定向到路线
我想从视图重定向:Javascript Laravel从视图重定向到路线,javascript,php,laravel,Javascript,Php,Laravel,我想从视图重定向: Route::get('/MyRoute', function () { return View::make('MyView'); }); 在MyView中,我想执行一些JavaScript,然后重定向到下载: // some imaginary javascript code, which will get executed <?php Redirect::to('/MyRoute2'); 但是我不能执行一些JavaScript代码。您没有返回重定向对
Route::get('/MyRoute', function () {
return View::make('MyView');
});
在MyView中,我想执行一些JavaScript,然后重定向到下载:
// some imaginary javascript code, which will get executed
<?php
Redirect::to('/MyRoute2');
但是我不能执行一些JavaScript代码。您没有返回重定向对象,就像您必须返回视图对象一样,您还必须返回重定向 因此,您必须
返回Redirect::to('/MyRoute2')代码>在控制器中
或者您可以使用JS执行重定向。您没有返回重定向对象,就像您必须返回视图对象一样,您还必须返回重定向
因此,您必须返回Redirect::to('/MyRoute2')代码>在控制器中
或者您可以使用JS执行重定向。您必须在视图中使用JS。所有php都是在页面呈现之前处理的,因此如果您想在一些js代码之后重定向,则需要从客户端调用重定向:
<script>
// your "Imaginary javascript"
window.location.href = '{{url("yoururl")}}';
// or
window.location.href = '{{route("myRoute")}}'; //using a named route
</script>
//你的“想象的javascript”
window.location.href='{{url(“yoururl”)}}';
//或
window.location.href='{{route(“myRoute”)}}'//使用命名路由
您必须在视图中使用JS。所有php都是在页面呈现之前处理的,因此如果您想在一些js代码之后重定向,则需要从客户端调用重定向:
<script>
// your "Imaginary javascript"
window.location.href = '{{url("yoururl")}}';
// or
window.location.href = '{{route("myRoute")}}'; //using a named route
</script>
//你的“想象的javascript”
window.location.href='{{url(“yoururl”)}}';
//或
window.location.href='{{route(“myRoute”)}}'//使用命名路由
如何传递用户ID?如何传递用户ID?