解决node.js express框架的跨域问题;
2014-12-01 20:19
225 查看
在引用路由之前写下如下代码:
app.use('*', 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');
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",'3.2.1')
next();
});
即可用ajax完成跨域访问.
app.use('*', 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');
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",'3.2.1')
next();
});
即可用ajax完成跨域访问.
相关文章推荐
- Node.js后台配置解决跨域问题(express框架)
- 如何解决node.js中fs.rename文件跨域问题
- Node.js配合node-http-proxy解决本地开发ajax跨域问题
- node.js解决跨域问题
- vue+node.js跨域问题的解决
- Node.js配合node-http-proxy解决本地开发ajax跨域问题
- 【Node】node.js实现服务器的反向代理,解决跨域问题
- 解决js跨域问题
- js_跨域访问问题解决方法
- 如何解决js跨域问题
- 后台访问 JS解决跨域问题
- 【转】js 跨域访问问题解决方法
- js 跨域访问问题解决方法
- 解决js跨域问题
- Node.js Cannot find module 'xxx' 有关问题解决
- JS跨域访问问题解决方法
- 解决js跨域问题
- js解决cookie跨域访问的问题
- 配置apache反向代理,解决js跨域问题
- apache配置重定向解决js跨域问题