23 lines
589 B
JavaScript
23 lines
589 B
JavaScript
window.postWithHeader = function(url, method, headerKey, headerValue) {
|
|
fetch(url, {
|
|
method: method,
|
|
headers: {
|
|
[headerKey] : headerValue
|
|
}
|
|
}).then(res => {
|
|
if (res.redirected) {
|
|
window.location.href = res.url;
|
|
}
|
|
});
|
|
};
|
|
|
|
window.fetchWithHeaderAndReturnUrl = async function(url, method, headerKey, headerValue) {
|
|
const response = await fetch(url, {
|
|
method: method,
|
|
headers: {
|
|
[headerKey]: headerValue
|
|
}
|
|
});
|
|
const data = await response.json();
|
|
return data.url;
|
|
}; |