Reputation: 197
I have multiple functions, that call fetch():
function FetchData(...) {
(async () => {
...
var res = await fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({...})
});
...
})();
}
I would like get the header via a Global Variable (or better a function which returns the value), but this is not working yet.
Goal is:
function FetchData(...) {
(async () => {
...
var res = await fetch(url, {
method: 'POST',
ReturnHeader(),
body: JSON.stringify({...})
});
...
})();
}
Upvotes: 0
Views: 191
Reputation: 782775
Call the function in the value of the property.
function FetchData(...) {
(async () => {
...
var res = await fetch(url, {
method: 'POST',
headers: ReturnHeader(),
body: JSON.stringify({...})
});
...
})();
}
Upvotes: 1