I’m trying to write an AJAX script that will log me out of Laravel using a POST request:
$.ajax({
headers: {
'X-CSRF-Token': "{{ csrf_token() }}"
},
type: "POST",
url: '/logout',
success: function() {
window.location.replace('https://portal.nchinc.com/?logout=timeout');
}
});
The result is I just get redirected, the logout doesn’t take effect. What am I doing wrong?
Note: The CSRF token is being set to avoid a 401 unauthorized HTTP response.
Thanks for any help!
2
Answers
try like:
You should not need the header to be set, but
_token
is required to avoid Csrf validation failure.It works