Laravel && Fetch API
Post
var token = document.querySelector('[name=csrf_token]').getAttribute('content');
fetch('/submit-sth', {
method : 'post',
mode: 'cors',
headers: {
"Content-Type": "application/json",
"Accept": "application/json, text-plain, */*",
"X-Requested-With": "XMLHttpRequest",
"X-CSRF-TOKEN": token
},
body: JSON.stringify({id: id, sth: sth})
})
.then((res) => res.json())
.then((res) => {
//console.log(res)
})
.catch((error) => console.log(error))
Get
fetch('/get-sth-by-id/888')
.then((res) => res.json())
.then((res) => {
})
.catch((error) => console.log(error))