【问题标题】:Laravel 4- redirect to a route inside javascript code Blade templateLaravel 4-重定向到javascript代码刀片模板中的路由
【发布时间】:2014-06-06 18:46:40
【问题描述】:

我正在尝试使用 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') 时它不起作用,正确的语法是什么,抱歉我的英语不好。

【问题讨论】:

    标签: javascript php redirect laravel-4 blade


    【解决方案1】:

    $url=URL::to('foo'); // 任何其他路由名称,例如 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

    【讨论】:

      猜你喜欢
      • 2019-08-28
      • 2016-12-18
      • 2014-04-21
      • 2017-08-24
      • 2015-07-12
      • 2015-08-04
      • 1970-01-01
      • 2017-07-07
      • 2014-05-10
      相关资源
      最近更新 更多