var request = new Request("http://mywebsite.com/login.php", {
method: 'POST',
mode: 'cors',
redirect: 'follow',
headers: new Headers({
Accept : 'application/json',
'Content-Type' : 'application/json'
}),
body : JSON.stringify ({
username : 'username',
password : 'password'
})
});
// Now use it!
fetch(request).then((response)=>response.json()).
then((res)=>{
console.log(res);
});
npm install axios
axios.post('mywebsite.com/login.php', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});