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:
$.ajax({
url: "http://localhost:8080/login",
type: 'POST',
data: formData,
error : function(err) {
console.log('Error!', err)
},
success: function(data) {
console.log('Success!')
localStorage.setItem('token', data.id_token);
}
});
Send the Request
$.ajax({
url: "http://localhost:8080/login",
type: 'GET',
// Fetch the stored token from localStorage and set in the header
headers: {"Authorization": localStorage.getItem('token')}
});
After reading the Axios features, the last one is: Client side support for protecting against XSRF . Does jQuery ajax not support that? Would I have to do anything extra to make this protection? Is there anything else that makes it worth using another library like Axios instead of jQuery?