News for hackers. Stuff that matters.
Re:How to manage HTML DOM with vanilla JavaScript only? by tyingq on Thursday April 02, 2020 @09:15AM (#22758541)
A 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.

Re:How to manage HTML DOM with vanilla JavaScript only? by untog on Thursday April 02, 2020 @09:23AM (#22758640)
For me the Fetch API is basically that:

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.
Re:How to manage HTML DOM with vanilla JavaScript only? by leetrout on Thursday April 02, 2020 @09:40AM (#22758806)
It 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.
Re:How to manage HTML DOM with vanilla JavaScript only? by untog on Thursday April 02, 2020 @09:56AM (#22758960)
What’s not nice about POST?

    fetch(url, {
      method: “POST”,
      body: “a body”
    })
Re:How to manage HTML DOM with vanilla JavaScript only? by tyingq on Thursday April 02, 2020 @09:51AM (#22758914)
It has some limitations as well around timeouts, cross site cookies, and progress tracking (uploads, for example).
Re:How to manage HTML DOM with vanilla JavaScript only? by untog on Thursday April 02, 2020 @09:55AM (#22758948)
Sure, but those aren’t common uses for $.ajax. Fetch can get you 95% of the way there.
Re:How to manage HTML DOM with vanilla JavaScript only? by austincheney on Thursday April 02, 2020 @09:34AM (#22758753)
How 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/XMLHttpRequ...

Re:How to manage HTML DOM with vanilla JavaScript only? by validuser on Thursday April 02, 2020 @09:22AM (#22758619)
Re:How to manage HTML DOM with vanilla JavaScript only? by donohoe on Thursday April 02, 2020 @09:37AM (#22758782)
Added!

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.

Re:How to manage HTML DOM with vanilla JavaScript only? by icedchai on Thursday April 02, 2020 @09:32AM (#22758726)
So why not just use jQuery?
Re:How to manage HTML DOM with vanilla JavaScript only? by tyingq on Thursday April 02, 2020 @09:35AM (#22758755)
I like their ajax implementation, but don't need the rest of the library.
Re:How to manage HTML DOM with vanilla JavaScript only? by edoceo on Thursday April 02, 2020 @10:00AM (#22759001)
Maybe try Zepto?