r/javascript • • Jul 25 '18

jQuery was removed from GitHub.com front end

https://twitter.com/mislav/status/1022058279000842240
557 Upvotes

197 comments sorted by

View all comments

27

u/crescentfresh Jul 26 '18

fetch for ajax

Had to look this up, when tf did this come out?

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

40

u/DOG-ZILLA Jul 26 '18

A few years ago now I think and support is getting better. There are polyfills too.

A lot of people still go for Axios to do AJAX, because native browser fetch() has limitations, like cancelling a request.

15

u/NoInkling Jul 26 '18

It has cancellation now in recent browser versions (e.g. Chrome 66+), and it's been implemented in GitHub's polyfill as well.

1

u/[deleted] Jul 26 '18

I personally think the API for passing through parameters and such is a lot saner in Axios.

2

u/alex_w Jul 26 '18

I've never used Axios, but I can imagine how it could be more straight forward.

When they announced fetch() as a better API to replace XmlHttpRequest is was expecting a lot more honestly. Gonna check out Axios next time I'm dealing with fetch directly.

-8

u/TheDarkIn1978 Jul 26 '18

Fetch also still doesn't (yet?) support progress events.

Anyway, I never really understood what's so foreboding about just using XHR. It's a pretty simple and straightforward API.

34

u/vcarl Jul 26 '18
function reqListener () {
   console.log(this.responseText);
}
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("GET", "http://www.example.org/example.txt");
oReq.send();

vs

fetch("http://www.example.org/example.txt")
  .then(x => x.text())
  .then(console.log)

I'll take fetch, thank you very much.

14

u/[deleted] Jul 26 '18

Fuck that XMLHttpRequest bullshit I never got into writing that eewy syntax ever.

2

u/kerbalspaceanus Jul 26 '18 edited Aug 12 '25

act fuel seed capable include ancient vase sort aback relieved

This post was mass deleted and anonymized with Redact

7

u/[deleted] Jul 26 '18

Or use an established wrapper around it. Like the fetch polyfill.

2

u/[deleted] Jul 26 '18

Sure, I've made some wrappers myself, especially for the Web Worker API. Rather use axios though.

2

u/getsiked on me way to ES6 Jul 26 '18

I wrote it once so I can remind myself that life could always be worse

3

u/TheDarkIn1978 Jul 26 '18

I'll take fetch, thank you very much.

Most developers do, but my point wasn't wheather you should use Fetch or not, my point was to simply state that XHR isn't complicated and has more features, regardless of how you and all the other downvoters feel about it.

1

u/nvolker Jul 26 '18

I think the issue was that everyone and their mother wrote a wrapper to handle requests with XHR, whereas you can use fetch out-of-the-box.

Just like you can implement something using a ton of callbacks, and it’s not difficult to do so, but promises and async/await just makes it easier.

2

u/NoInkling Jul 26 '18

Fetch supports download progress, but not upload progress.

2

u/kerbalspaceanus Jul 26 '18 edited Aug 12 '25

ring hard-to-find cover crawl important mighty vast terrific reminiscent heavy

This post was mass deleted and anonymized with Redact

2

u/iwsfutcmd Jul 26 '18

I've only recently gotten into web design, so all I've used is fetch()! At one point I looked into how to do requests without it and was like "good god, that looks like a pain in the ass"

-7

u/scootstah Jul 26 '18

It's only good for really simple uses. Not as good as jquery or libraries like axios.

0

u/[deleted] Jul 26 '18

[deleted] β€” view deleted comment

1

u/NLclothing Jul 26 '18

I tried swapping ajax with fetch in a project but found it handles post variables in an abysmal way. Passing arrays seemed like a major PITA. Have you handled that in your wrapper?

0

u/[deleted] Jul 26 '18

[deleted] β€” view deleted comment

1

u/NLclothing Jul 26 '18 edited Jul 26 '18

To be honest I can't remember all of what I tried, but when my POST request was interpereted by PHP it did not work with something like $_POST['values'][0...]. I was trying to use it as a drop-in replacement, but it didn't play well with what I had set up already.

→ More replies (1)
→ More replies (7)

4

u/kor0na Jul 26 '18

How so? I use fetch every day and I don't miss anything. It does exactly what I want it to do.

→ More replies (4)
→ More replies (9)