问题
I am stuck with this error. please help..
XMLHttpRequest cannot load. Request header field x-access-token is not allowed by Access-Control-Allow-Headers.
回答1:
Your server should return that it accepts custom headers (like x-access-token). For example, if you are using nodejs with expressjs, try this:
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*"); // keep this if your api accepts cross-origin requests
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, X-Access-Token");
next();
});
If your server is in PHP, you need to do the same:
header("Access-Control-Allow-Origin: *"); // keep this if your api accepts cross-origin requests
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, X-Access-Token");
Ps: Access-Control-Allow-Headers doesn´t accept wildcards '*' as value.
来源:https://stackoverflow.com/questions/39345378/request-header-field-x-access-token-is-not-allowed-by-access-control-allow-heade