Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
-1
rated 0 times [  5] [ 6]  / answers: 1 / hits: 21672  / 10 Years ago, sat, may 10, 2014, 12:00:00

I want to redirect from a view:



Route::get('/MyRoute', function () {
return View::make('MyView');
});


In MyView I want to execute some JavaScript and then Redirect to a download:



// some imaginary javascript code, which will get executed

<?php

Redirect::to('/MyRoute2');


I can't seem to find a way, which will work. What am I doing wrong?



Of course I could change the /MyRoute to:



Route::get('/MyRoute', function () {
return Redirect::to('/MyRoute2');
});


but then I can't execute some JavaScript code.


More From » php

 Answers
19

You have to use JS for that, inside your view. All php is handled before the page renders, so if you want to redirect after some js code you need to call the redirection from the client-side:



<script>
// your Imaginary javascript
window.location.href = '{{url(yoururl)}}';
// or
window.location.href = '{{route(myRoute)}}'; //using a named route
</script>

[#71097] Thursday, May 8, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ayleen

Total Points: 447
Total Questions: 88
Total Answers: 109

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
;