5 ms·
I would totally use this but its missing ajax.
by thekingshorses 11y ago
I would totally use this but its missing ajax.
- X-Istence 11y agoUse the new fetch API instead.
- recursive 11y agohttps://developer.mozilla.org/en-US/docs/Web/API/Fetch_API https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API It's not ready.
- jorde 11y agoFetch is great and there's a tiny polyfill from GitHub to patch IE and Safari https://github.com/github/fetch https://github.com/github/fetch
- marktucker 11y agoI find fetch very painful to use since the promises don't reject on non-2XX! I use axios instead. This is especially so sad when using async/await :( https://github.com/whatwg/fetch/issues/18 https://github.com/whatwg/fetch/issues/18 fetch(url) .then((res) => { if (res.statusCode < 200 || res.statusCode > 299) { throw new Error("Why do I have to write this with every request?"); } });
- Zecc 11y agoFWIW, the Response object has the `ok` property [1] as a shorcut. It is equivalent to testing whether status is between 200 and 299. If it's really that important to you, you can always create your own wrapper around fetch function fetch2(uri) { return fetch(uri).then( (res) => { if (res.ok) { return Promise.resolve(res); } else { return Promise.reject("Request failed with status "+res.status+" ("+res.statusText+")"); } } ); } fetch2('some-url') .then( (res) => { console.log('Success', res.status, res.statusText); }) .catch( (err) => { console.log(err); }); [1]: https://developer.mozilla.org/en-US/docs/Web/API/Response/ok
- jest3r1 11y agoIn IE?
- franciscop 11y agoThere are many alternatives: - Zepto : http://zeptojs.com/ http://zeptojs.com/ - Umbrella JS (mine): http://umbrellajs.com/ http://umbrellajs.com/ - Nano ajax: https://github.com/yanatan16/nanoajax https://github.com/yanatan16/nanoajax