考虑到这一系列的ajax召唤FriendsController@destroy
$.ajax({
url: '/dashboard/friends/' + id,
type: 'DELETE',
data: { src: 'show' },
success: function(response) {
}
});
Run Code Online (Sandbox Code Playgroud)
删除程序完成后我怎么能return Redirect::route('dashboard.friends.index')在里面FriendsController?我想这是试图将响应返回给AJAX,后者不知道如何反应.
我可以,window.location.href = '/dashboard/friends'但我希望Flash成功消息到我无法用AJAX做的视图.
我找到了最简单的方法。只要在ajax成功中再次使用相同的url。假设朋友是你的路线名称
$.ajax({
url: '/dashboard/friends/' + id,
type: 'DELETE',
data: { src: 'show' },
success: function(response) {
window.location.href = "friends";
}
});
Run Code Online (Sandbox Code Playgroud)
这样,您可以根据需要放置重定向或Flash会话消息。
这是我自己解决这个问题的方法。对于执行模型的 AJAX 删除等功能,它将提示确认模式,执行删除,闪烁消息并重定向到提供的路线。
data设置完成后,可以通过将适当的属性传递给原始删除按钮或链接来动态完成。
| 归档时间: |
|
| 查看次数: |
21006 次 |
| 最近记录: |