import 'whatwg-fetch';
// fetch polyfill
const url = <code>https://abc.xgqfrms.xyz/some-url</code>;
const headers = new Headers({
'Content-Type': 'text/plain',
'X-My-Custom-Header': 'CustomValue'
});
const datas = JSON.stringify(
{
user: "username",
pwd: "password"
}
);
const method = <code>POST</code>;
const request = new Request(url, {
headers: headers,
method: 'POST',
mode: 'cors',
redirect: 'follow',
body: datas
});
fetch(
request
).then(
(response) => response.json()
).catch(
(err) => {
console.log(<code>err</code>, err);
throw new Error("Whoops, An Error occurred!");
}
);
Created
January 14, 2018 13:43
-
-
Save xgqfrms-GitHub/64972e969d7491a7f845b9d69a9ba743 to your computer and use it in GitHub Desktop.
whatwg-fetch & fetch polyfill
https://learning.xgqfrms.xyz/webpack-next/000-xyz/no-jquery-modal/modal/libs/test.html
https://cdn.xgqfrms.xyz/json/news/560956639429
https://cdn.xgqfrms.xyz/json/news/560956639429.json
https://github.com/gildata/RAIO/issues/280#issuecomment-355833553
fetch(`https://cdn.xgqfrms.xyz/json/badges.json`)
.then((res) => res.json())
.then((data) => console.log(data));
fetch(`https://cdn.xgqfrms.xyz/json/badges.json`)
.then((res) => res.json())
.then((data) => {
console.log(data.user);
console.log(data.courses);
console.log(data.badges);
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/xgqfrms-GitHub/039e67b096ce204379b2aba95fbd494d
https://gist.github.com/xgqfrms-GitHub/b252342f28497eadc96134a5873814fb
https://learning.xgqfrms.xyz/webpack-next/000-xyz/no-jquery-modal/modal/libs/test.html
https://cdn.xgqfrms.xyz/json/news/560956639429
https://cdn.xgqfrms.xyz/json/news/560956639429.json
https://github.com/gildata/RAIO/issues/280#issuecomment-355833553