axios always sends two requests and the first time there is an options request, how to get rid of it?
the request header contains token
axios always sends two requests and the first time there is an options request, how to get rid of it?
the request header contains token
cannot be removed. The keywords simple request and non-simple request .
either do not use complex requests (such as get
request)..) The complex request browser will send the pre-check command (options), which is the behavior of the browser and cannot be controlled.
I guess you are concerned that sending two HTTP requests feels a bit wasteful, so you can actually use Access-Control-Max-Age
to cache the options for a certain period of time.
(to say something beside the point.. The front end is excused for not knowing HTTP
, but it's a bit too much for the back end not to know the basics.)
related knowledge can be understood.
backend processing, post request will be sent twice, the first is with option, the second is post request, https://developer.mozilla.org.
part of the information, you can check this
Previous: The problem of variable reference in vue2
Next: Does window.location.href have callback functions for successful and failed jumps?