4 ms·
I'd be interested to see if other people have similar go-to vanilla JS? If so, can you share a link here? This one is mine: https://github.com/donohoe/content
by donohoe 7y ago
I'd be interested to see if other people have similar go-to vanilla JS? If so, can you share a link here?
This one is mine:
https://github.com/donohoe/content/blob/master/posts/javascript-returns.md https://github.com/donohoe/content/blob/master/posts/javascr...
(I follow basic ES6 syntax but easy to switch as needed)
- tyingq 7y agoA vanilla JS replacement for jQuery's ajax functionality, that worked on older browsers, would be welcome. Edit: To clarify, a drop in replacement is what I was looking for.
- validuser 7y agohttp://youmightnotneedjquery.com/#ajax http://youmightnotneedjquery.com/#ajax
- untog 7y agoFor me the Fetch API is basically that: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API fetch("http://www.example.com").then(res => res.json()).then(json => {}) Only big downside is no IE11 support but thankfully I don't have to worry about that so much these days.
- leetrout 7y agoIt still doesn't go POST in a nice way like the jQuery API does BUT it is not worth bringing jQuery to the page just for making requests with slightly nicer syntax.
- untog 7y agoWhat’s not nice about POST? fetch(url, { method: “POST”, body: “a body” })
- tyingq 7y agoIt has some limitations as well around timeouts, cross site cookies, and progress tracking (uploads, for example).
- untog 7y agoSure, but those aren’t common uses for $.ajax. Fetch can get you 95% of the way there.
- icedchai 7y agoSo why not just use jQuery?
- austincheney 7y agoHow old do you need to go? It looks like most of the standard XHR was working in IE7 except for the withCredentials flag. https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequ...
- donohoe 7y agoAdded! I don't know how far back it will help with old browsers. I'd need to test that and it will take awhile. JSON.parse will throw a few older browsers by itself.