推荐阅读:https://segmentfault.com/a/1190000012469713
正常的ajax请求
CORS 配置解决跨域
Node.js后台配置(express框架)
app.all('*', function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); // 主要是配置这个!!! res.header("Access-Control-Allow-Headers", "X-Requested-With"); res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS"); res.header("X-Powered-By", ' 3.2.1') //这段仅仅为了方便返回json而已 res.header("Content-Type", "application/json;charset=utf-8"); if(req.method == 'OPTIONS') { //让options请求快速返回 res.sendStatus(200); } else { next(); }});