I'm try to request an ajax Post with laravel, they provided me a API with username and password authorization. how can I solve this.
here my code below.
$("#login_page").submit(function (e) {
$.ajax({
url: "https://api.seasolutions.ph/frontend/login/",
type: "POST",
headers: {
'Authorization': 'Basic ' + '***=',
},
data: $("#login_page").serialize(), //only input
success: function (response) {
console.log(response);
}
});
e.preventDefault();
});
You have to add your csrf_token
I think.
Here's the documentation.
headers: {
'Authorization':'Basic ' + '***=',
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
If it doesn't work, you need to add <meta name="csrf-token" content="{{ csrf_token() }}">
into your main blade file.