php – 当由AJAX调用时,Laravel重定向到从控制器路由

前端之家收集整理的这篇文章主要介绍了php – 当由AJAX调用时,Laravel重定向到从控制器路由前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
鉴于这个调用FriendsController @ destroy的ajax块
$.ajax({
    url:     '/dashboard/friends/' + id,type:    'DELETE',data:    { src: 'show' },success: function(response) {
    }
});

删除过程完成后,如何在FriendsController中返回Redirect :: route(‘dashboard.friends.index’)?我想这是试图将响应返回给AJAX,后者不知道如何反应.

我可以只是window.location.href =’/ dashboard / friends’,但我想将一条成功消息发送到我无法用AJAX做的视图.

我找到了最简单的方法.
在你的ajax成功中再次使用相同的url.假设朋友是你的路线名称
$.ajax({
    url:     '/dashboard/friends/' + id,success: function(response) {
       window.location.href = "friends";
    }
});

这样你就可以根据需要放置重定向或flash会话消息.

原文链接:https://www.f2er.com/laravel/134178.html

猜你在找的Laravel相关文章