[英]Laravel 4- redirect to a route inside javascript code Blade template
我正在嘗試使用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>
當我使用返回Redirect::route('home')
它不起作用,這樣做的正確語法是什么,抱歉我的英語不好。
$ 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.