using fetch in laravel code example
Example: laravel fetch post
fetch(url, {
headers: {
"Content-Type": "application/json",
"Accept": "application/json, text-plain, */*",
"X-Requested-With": "XMLHttpRequest",
"X-CSRF-TOKEN": token
},
method: 'post',
credentials: "same-origin",
body: JSON.stringify({ name: name, number: number }) })
.then((data) => {
form.reset();
window.location.href = redirect;
})
.catch(function(error) {
console.log(error);
});
}