AJAX alternative to jQuery


#1

I am not thrilled with the verbosity of jQuery’s ajax syntax. Is it possible to use something other than jQuery when fetching data?

I really like axios as a simple and terse alternative to jQuery.ajax/get/post. It has more options and is much more lightweight than jQuery’s old syntax.

So I tried installing axis.

npm install axios --save
import axios from 'axios';

That didn’t work, and maybe it should have? Build failed, and I’m not sure why.

bower install axios --save
app.import(....);

That didn’t fail, but it also didn’t work.

Any thoughts?


#2

https://github.com/stefanpenner/ember-fetch is quite nice. There is also https://github.com/ember-cli/ember-ajax


#3

If you dont want to use jQuery, I would highly recommend you to use vanilla JS. Perhaps write a service, or something like that?

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


#4

How is .get and .post verbose?


#5

Thanks @jasonmit. That is close to what I need. Fetch only does one thing, and I like it. Used it for a React project. But it doesn’t solve the other verbs.

The problem with using vanilla js is that then I have to write the VERY verbose syntax of the xmlhttprequest then wrapping it in a Promise. So I may as well just stick with jquery.

You just listed 2 verbs out of 4 that are most used in APIs. Yes, jquery does fine with those 2. It does fine for all of them, except PUT/PATCH makes you define settings and then attach callbacks there.

A library like axios is much more succinct and already written for promises and ES6. Best thing to do? Take @stefan and the ember-cli way and make it installable. A fun endeavor when if I have time. For now I will stick with jquery


#6

What verbs doesn’t fetch support? Look at it more closely.


#7

Right here bra’ http://microjs.com/#ajax


#8

I recommend https://github.com/tulios/mappersmith, it’s not just an AJAX alternative but it will fit like a glove.