Help with Javacript to Laravel
I am using an API and they have given me a Javascript example of how to get a token. However, I need help with getting that token back to Laravel. I think I need a POST function of some sort but I do not know where or how. Please help. Thanks.
<script></script><script>
// Part 2. Initialize & configure the client library
document.addEventListener("DOMContentLoaded", function() {
var tellerConnect = TellerConnect.setup({
applicationId: "app_nadv4thdhoronhtebc000",
environment: "sandbox",
onInit: function() {
console.log("Teller Connect has initialized");
},
// Part 3. Handle a successful enrollment's accessToken
onSuccess: function(enrollment) {
console.log("User enrolled successfully", enrollment.accessToken);
},
onExit: function() {
console.log("User closed Teller Connect");
}
});
// Part 4. Hook user actions to start Teller Connect
var el = document.getElementById("teller-connect");
el.addEventListener("click", function() {
tellerConnect.open();
});
});
</script>
Hello,
Yes indeed you are right, it will be more or less a standard JS AJAX request. You could use fetch
or a library like Axios depending on your personal preferences.
fetch('/your-larave-route', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'url': '/your-larave-route',
"X-CSRF-Token": document.querySelector('input[name=_token]').value
},
})
Also remember to include the @csrf
helper in your blade view so that the X-CSRF-Token
could have a correct value.
Let me know how it goes!
Best,
Bobby
















Thank you!















