Laravel 5.8登录后重定向

时间:2019-07-04 15:54:49

标签: php laravel laravel-5.8

在我的Laravel应用程序中,默认登录页面以及下拉菜单中的登录表单。按照我现在的设置,成功登录后,用户将被重定向到索引页面,但是,如果用户在下拉菜单中使用登录表单,我希望他停留在已经存在的页面上。

有没有比通过下拉菜单添加单独登录方法更好的做法?

1 个答案:

答案 0 :(得分:0)

您可以使用option (maxrecursion 0)axios登录并停留在页面上。

ajax的示例,在脚本中编写如下内容

axios

$("body").on("submit", "#login-form", function (e) { var action = $(this).attr("action"); // your login url e.preventDefault(); axios.post(action, $(this).serialize()) .then(function (response) { // do something from the response // i.e. display error or update navbar to logged in view }) .catch(function (error) { // handle error here }); }); 的示例,在脚本中编写如下内容

ajax

在两个示例中,我都假定您将拥有一个ID为$("#login-form").submit(function(event){ event.preventDefault(); //prevent default action var post_url = $(this).attr("action"); //get form action url var request_method = $(this).attr("method"); //get form GET/POST method var form_data = $(this).serialize(); //Encode form elements for submission $.ajax({ url : post_url, type: request_method, data : form_data, beforeSend: function() { // show loading or whatever }, success: function(data) { // do something from the response // i.e. display error or update navbar to logged in view }, error: function(xhr) { // if error occured var status = xhr.statusText; var response = JSON.parse(xhr.responseText); // handle error here } }); }); 的登录表单

相关问题