Laravel 4-重定向到javascript代码中的路径刀片模板

时间:2014-04-22 11:57:44

标签: javascript php redirect laravel-4 blade

我试图使用javascript和刀片引擎编写一个简单的重定向,这是我想要做的一个例子:

javascript代码:

<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>

当我使用return Redirect::route('home')时,它不起作用,这样做的正确语法是什么,对不起我的英语不好。

1 个答案:

答案 0 :(得分:6)

$网址= URL ::到( '富'); //任何其他路由名称,如home,或使用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')}}";
   }
...

更多信息:http://laravel.com/docs/routing