Вы можете использовать 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
, в вашем скрипте напишите что-то вроде этого
$("#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
}
});
});
В обоих примерах я предполагаю, что у вас будет форма входа с идентификатором login-form