第一个办法是:cors
但是抱歉宝宝没用太好所以出现了第二个简单粗暴的办法。
从网上得知的第二个办法 是:
在node服务器后台express的app.js中加入一段代码:
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , application/x-www-form-urlencoded');
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1')
res.header("Content-Type", "application/json;charset=utf-8");
next();
});
但是注意注意注意!!!!!
这段代码不是在最后追加的,而是最好放到最前方,不然你总会遇到一些错误~~
比如:
Font from origin 'http://lovefeel.top' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.lovefeel.top' is therefore not allowed access.
所以 有时候位置很重要,不然会不舒服很久~~~~。