加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-14 19:45:04 所属栏目:大数据 来源:网络整理
导读:鉴于这个调用FriendsController @ destroy的ajax块 $.ajax({ url: '/dashboard/friends/' + id,type: 'DELETE',data: { src: 'show' },success: function(response) { }}); 删除过程完成后,如何在FriendsController中返回Redirect :: route(‘dashboard.frie
鉴于这个调用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会话消息.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读