admin管理员组

文章数量:1310854

I'm trying to write a simple redirection using javascript and blade engine, and this is an example of what i want to do:

javascript code:

<p>Click the button to go to the home page</p>

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>

<script>
function myFunction()
{
    var x;
    var r=confirm("Are you sure you want to leave this page ?");
    if (r==true)
    {
      //Redirect to home
    }
    else
    {
     //stay here
    }
    document.getElementById("demo").innerHTML=x;
}
</script>

when i use return Redirect::route('home') it does not work, what is the right syntax to do that, and sorry for my bad english.

I'm trying to write a simple redirection using javascript and blade engine, and this is an example of what i want to do:

javascript code:

<p>Click the button to go to the home page</p>

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>

<script>
function myFunction()
{
    var x;
    var r=confirm("Are you sure you want to leave this page ?");
    if (r==true)
    {
      //Redirect to home
    }
    else
    {
     //stay here
    }
    document.getElementById("demo").innerHTML=x;
}
</script>

when i use return Redirect::route('home') it does not work, what is the right syntax to do that, and sorry for my bad english.

Share Improve this question asked Apr 22, 2014 at 11:57 BaHar AyØubBaHar AyØub 3373 gold badges6 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

$url=URL::to('foo'); // any other route name, like home, or use URL::route()

<script>
function myFunction()
{
   var x;
   var r=confirm("Are you sure you want to leave this page ?");
   if (r)
   {
      window.location="{{URL::to('home')}}";
   }
...

More info: http://laravel./docs/routing

本文标签: phpLaravel 4 redirect to a route inside javascript code Blade templateStack Overflow