Javascript fetch function sends OPTIONS instead of POST. I test from localhost.
function getTokenAction() {
fetch(full_url, {
method: 'POST',
body: queryString,
headers: {
'Access-Control-Allow-Methods': 'POST, GET, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'origin, x-requested-with, content-type',
'Accept': 'application/json',
// 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
'Content-Type': 'application/json;charset=UTF-8'
}
}).then(function (response) {
console.log(response.statusText);
}).catch(function (error) {
console.log(error);
});
I could make it work using JQuery. But fetch function still doesn't work.
function getTokenJquery() {
let settings = {
"async": true,
"crossDomain": true,
"url": full_url,
"method": "POST",
"headers": {
"content-type": "application/x-www-form-urlencoded",
"accept": "application/json"
},
"data": {
client_id: 'd5eecb6e23eadb3175c5cb51b2dfec1f74850c19',
client_secret: 'eff5fc8c1d57f69130d780cfa032aa30be0fb7f2',
grant_type: 'client_credentials'
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});