JavaScript AJAX Basics (retiring) jQuery and AJAX jQuery’s AJAX Shorthand Methods

Can I just use vanilla JS for AJAX calls? Jquery is almost too easy.

Sounds strange, but writing all those lines of vanilla JS made more intuitive sense to me than Jquery, it's almost too simple... as strange as that may sound.

Is it fine if I proceed not to use Jquery for AJAX calls?

4 Answers

Steven Parker
Steven Parker
176,604 Points

:bell: Hi, I got alerted by your tag.

Coding AJAX can be a pain (or "challenge") using basic XMLHttpRequests. You might try it once or twice for a learning exercise, but I can't imagine you'd want to do that in general. The new "fetch" interface is about as easy to use as jQuery, but one advantage jQuery still has is that it recognizes and handles common CORS (security) issues that can be a problem with either the basic interface or fetch.

I'd probably favor "fetch" when there are no problems, and good old jQuery if there are CORS issues due to the server(s) not sending all the correct headers.

Great! And I'm assuming the ''fetch'' interface is more native to the browser, correct?

Steven Parker
Steven Parker
176,604 Points

Yes, "fetch" is part of JavaScript.

Paul Scanlon
PRO
Paul Scanlon
Pro Student 26,724 Points

Hey

Try reading this.

(https://www.w3schools.com/xml/xml_http.asp)

Also there is the fetch api which is more flexible and promise based.

Hope this helps

Happy coding

Paul

Hey Paul, thanks for help and link, is it fair to say that this current course on Jquery AJAX handling (these: https://teamtreehouse.com/library/ajax-basics/jquery-and-ajax/the-office-status-project-revisited) are a bit outdated and would be wiser to follow what you sent me?

Johan Uribe
Johan Uribe
2,677 Points

I was also wondering if jquery and Ajax were outdated technologies worth learning.

Steven Parker
Steven Parker
176,604 Points

There's a lot more to jQuery than just AJAX, and a lot of modern frameworks depend on it, so I don't think it's likely to become outdated anytime soon.

And while you may only code AJAX using jQuery or Fetch, it's still good to at least know how the primitive calls work.