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:
// `xsrfCookieName` is the name of the cookie to use as a value for xsrf token
xsrfCookieName: 'XSRF-TOKEN', // default
// `xsrfHeaderName` is the name of the http header that carries the xsrf token value
xsrfHeaderName: 'X-XSRF-TOKEN', // default
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?”
I would say most definitely. A library dedicated to handling http decouples the process from your application framework or presentation library.