ajax请求node.js接口时出现跨域问题Access-Control-Allow-Origin
2015-05-29 17:36
856 查看
ajax请求node.js接口出现了如下的错误:
XMLHttpRequest cannot load http://xxx.xxx.xx.xx:8888/getTem?cityId=110105&date=2015-03-04. No ‘Access-Control-Allow-Origin‘ header is present on the requested resource. Origin ‘null‘ is therefore not allowed access.
百度了一下,原来是缺少Access-Control-Allow-Origin属性,那么在node.js输出时把Access-Control-Allow-Origin属性加上就好了,如下
response.writeHead(200, {‘Content-Type‘: ‘text/json;charset=utf-8‘,‘Access-Control-Allow-Origin‘:‘*‘});
谷歌查了一下,原来Access-Control-Allow-Origin来限制请求域名的。 点我查看该属性的解释
XMLHttpRequest cannot load http://xxx.xxx.xx.xx:8888/getTem?cityId=110105&date=2015-03-04. No ‘Access-Control-Allow-Origin‘ header is present on the requested resource. Origin ‘null‘ is therefore not allowed access.
百度了一下,原来是缺少Access-Control-Allow-Origin属性,那么在node.js输出时把Access-Control-Allow-Origin属性加上就好了,如下
response.writeHead(200, {‘Content-Type‘: ‘text/json;charset=utf-8‘,‘Access-Control-Allow-Origin‘:‘*‘});
谷歌查了一下,原来Access-Control-Allow-Origin来限制请求域名的。 点我查看该属性的解释
相关文章推荐
- Node.js 函数
- Node.js 路由
- Node.js模块系统
- Node.js 事件
- Node.js 路由
- NodeJS的简介和安装配置
- sublime text2 nodejs插件安装
- nodejs代码修改记录
- queue-fun —— nodejs下基于Promise的队列控制模块。
- hadoop中NameNode、DataNode、Secondary、NameNode、JobTracker TaskTracker介绍
- Node.js缓冲模块Buffer
- JsonNode使用
- 【译】 Node.js v0.12的新特性 -- 性能优化
- nodejs npm包管理常用命令介绍
- Json字符串转JsonNode
- nodejs npm install全局安装和本地安装的区别
- XPath语法 在.net(C#)中使用XPath示例 doc.selectsinglenode("xpath")
- XPath语法 在.net(C#)中使用XPath示例 doc.selectsinglenode("xpath")
- Nodejs学习笔记(一)--- 简介及安装Node.js开发环境
- Ubuntu14.04LTS下安装Node.js&NPM以及个人博客hexo的初始化配置