XMLHttpRequest is an object in JavaScript that allows you to send AJAX requests to the server, it allows you to get a response from the server usin...
For further actions, you may consider blocking this person and/or reporting abuse
It's 2020, use promise-based
fetch()
instead.I agree that you there are better solutions now. It's always good to refresh on the underlying principles and workings though
Is using
var
and non-strict equality (==
) a part of refreshing on the underlying principles?Using var is fine for these examples as it is block scoped. I could have use the new let/const keywords plus non-strict equality, etc, etc. But for just showing the basics of XMLHttpRequest they're not needed and it would have over complicated the simple examples.
There's no point in using legacy and problematic syntax such as
var
and==
. For beginners, it makes sense to show correct examples of modern JavaScript. We don't speak Old Slavonic teaching kids Russian, so why should we use the legacy syntax when teaching people how to code?The last example is even incorrect,
XMLHttpRequest
will not doJSON.stringify()
automatically for you. Try running this code in the console:It sends
[object Object]
instead of JSON you expect.As you have pointed out, a more modern approach to this problem is to use a library such as axios. However, some people (not everyone) enjoy learning about the behind the scenes "magic" that goes into these libraries. I agree, you shouldn't teach beginners bad habits, but they should also know where you're able to use var/let and what the differences are. Imagine you're working for a client who demands vanilla JS or a specific browser compatibility, etc.
Usually there is no need for even axios, because
fetch
is enough for most of the use cases. And there is Babel for compatibility.Okay, my point is that you clearly don't have a lot of experience in JavaScript and software engineering. This is totally okay, but if you're not confident in what you're doing, please, don't write articles trying to teach people – you mislead them.
Your content, in general, is not high-quality, most of your articles are basically retelling the docs. And usually retelling inaccurately, this is the problem. You don't make any value to anyone.
It's up to you for sure, though I suggest you finish your bachelor's, work full-time for a few years and get back to blogging with experience and understanding.
I appreciate the feedback but it is very presumptuous and condescending, thanks
As I will almost always wrap in
new Promise
anyway, I would suggestaxios
, which isXMLHttpRequest
based and Promise based.Of course,
fetch
is already a Promise.Yes I agree, axios is a brilliant little library to handlr async requests