Axios Vs Jquery Ajax

Posted on  by admin
Modified2 years, 7 months ago.

I've been a jQuery user since forever. But now I'm building my first API that uses JWT for authentication.

This said, most tutorials I find online to consume this API with authentication headers use Axios to make these requests.

I am already using jQuery on the project, so, I would love to make simple jQuery ajax calls, but I'm not sure if there's any hard drawbacks to using it.

This would be my jQuery code:. Send the Request. After reading the Axios features, the last one is: Client side support for protecting against XSRF .

Does jQuery ajax not support that?

XXDebuggerXXDebugger
1,5712

110110 bronze badges. I do not see any explicit support for that in the jQuery $.ajax documentation. That being said, it is something you could do with the beforeSend setting. In the beforeSend you would modify the jqHXR to include your XSRF information. @charlietfl mentioned you can also do this in global ajaxSend() so it is applied to all instances of $.ajax().

This is what axios is doing:. If you are already using jQuery in your project, and you can handle the XSRF yourself, then use $.ajax(). "Is there anything else that makes it worth using another library like Axios instead of jQuery?"

CueCue
2,629

Welcome to the Treehouse Community