After a general front-end library sends an ajax
request, the response object headers
will have X-Requested-With:XMLHttpRequest
but## The ajax
request sent by #axios does not have this field in the response header
axios in nodejs code?
扔个三星炸死你2017-07-05 10:38:01
I want to add X-Requested-With
header to every request:
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
To intercept the sent ajax, just use spy to replace XMLHttpRequest
with the original method.
I can’t figure out why axios doesn’t add this header by default. . .
天蓬老师2017-07-05 10:38:01
Are you sure it's an axios problem? Have you tried using another tool? Ajax and axios are just tools for transmitting http requests, so I want to point out that the ajax request sent by the poster's axios is wrong. In addition, I don't know your backend. How to write it? If no acceptable request header is configured when crossing domains, the specified header data will not be obtained. "Access-Control-Allow-Headers": "X-Requested-With"