Laravel 4-重定向到javascript代码中的路径刀片模板 [英] Laravel 4- redirect to a route inside javascript code Blade template

查看:87
本文介绍了Laravel 4-重定向到javascript代码中的路径刀片模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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代码:

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>

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

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.

推荐答案

$ URL =网址::到( '富'); //任何其他路由名称,如home,或使用URL :: route()

$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')}}";
   }
...

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

这篇关于Laravel 4-重定向到javascript代码中的路径刀片模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆