【问题标题】:Laravel not getting redirected properlyLaravel 没有正确重定向
【发布时间】:2018-04-14 23:22:32
【问题描述】:

在 Laravel 我有一个网络路由

  Route::get('/signout', 'GlobalController@getLogout');

我在页面中使用注销选项

<li>
    <a href="{{ url('signout') }}">
       <i class="icon-key font-red-thunderbird"></i> Log Out
    </a>
</li>

同样的方式我有一个ajax修改密码成功js脚本

function parseError(response)
{
        var res = 0;
        $.each(response, function(i, item){
                $('#'+i+'_message').html(item);
                if(item!=1)
                $('#'+i+'_message').css('display', (item!=1)?'block':'none');
                else
                res += parseInt(item);
        });
        if(res != 0 )
        {
                bootbox.alert("Password changed successfully..!");
                window.location='/signout';
        }
}

但是 window.location='/signout'; 并没有触及函数 getLogout() 而是屏幕正在切换到登录屏幕。

我在 getLogout 中编写了一组未执行的函数。可能是什么问题呢。

【问题讨论】:

  • 试试这个window.location.href = "{{URL::to('/signout')}}"
  • 这是一个JS文件
  • 我知道脚本是否在刀片文件中,它应该可以正常工作
  • 你可以从 href 属性中获取 url 吗? $('mylink').attr('href') ?另外,注销后您会被重定向到登录页面吗?这似乎很正常,因为行为不?如果没有,请检查您的控制器是否注销,也许它在检查用户是否已登录(中间件?)

标签: javascript php laravel


【解决方案1】:

你应该试试这个:

<script>
// your "Imaginary javascript"
 window.location.href = '{{url("yoururl")}}';
</script>

或

<script>
 window.location.href = '{{route("myRoute")}}'; 
</script>

【讨论】:

  • @VijayanandPremnath:请关注Link,希望对您有所帮助!!!
猜你喜欢
  • 2019-03-25
  • 1970-01-01
  • 2020-02-05
  • 2020-10-10
  • 2019-07-23
  • 2020-02-10
  • 2021-12-06
  • 2020-05-13
  • 1970-01-01
相关资源
最近更新 更多