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