You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
in my opinion, axios is ajax library,
I suggest you should add default head value,(headers["X-Requested-With"] = "XMLHttpRequest") just like jq;
because backend developer need this flag to distinguish ajax request from request,
in order to do some different request handling; such as error handling;
if there is an ajax request error happening ,we will return json (including error message)
if there is a http request error happening,we may redirect to other page or others
in some team,some people use jq,some people use axios,.......
so I suggest ......
You can set default headers for Axios on your browser:
https://github.com/axios/axios#custom-instance-defaults
This will accomplish your goal without modifying Axios.
Note that adding the
X-Requested-With
header makes the request "unsafe" (as defined by CORS), and will trigger a preflight request, which may not be desirable.
See
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Simple_requests
for more