转载和积累系列 - Nodejs 中GET方法实现
2012-09-10 09:14
447 查看
//GET方法,获取URL中的GET提交数据 this.get = function (name) { var getQuery= url.parse(_req.url).query; var getData = querystring.parse(getQuery); //getData数据 if (typeof(name) == 'object') { //数组形式传递进来 var temp = {}; for (var i = 0; i < name.length; i++) { if (getData[name[i]]) { temp[name[i]] = getData[name[i]]; } else { temp[name[i]] = ''; } } return temp; } else { if (getData[name]) { return getData[name]; } else { return ''; } } }
使用方法:
//获取单个 get('username'); //获取多个返回对象 get(['username', 'hello'])
相关文章推荐
- 转载和积累系列 - Nodejs实现多进程
- 转载和积累系列 - nodejs 实现cookie
- 转载和积累系列 - Nodejs 实现静态服务器
- [label][转载][JavaSript]querySelectorAll 方法相比 getElementsBy 系列方法有什么区别?
- 转载和积累系列 - Linux tar命令常用方法
- 转载和积累系列 - Nodejs HTTP多线程
- 使用Jquery中getJSON和getScript方法实现跨域(转载)
- querySelectorAll 方法相比 getElementsBy 系列方法有什么区别? ---转载自知乎
- 转载和积累系列 - HTTP 400状态解决方法和Cookie的限制
- 转载和积累系列 - Lua 有趣的面向对象实现
- 转载和积累系列 - nodejs服务器端开发
- 转载和积累系列 - Redis内核之数据结构实现
- 转载和积累系列 - js实现 hashMap
- 转载和积累系列 - hashmap 详细实现
- 转载和积累系列 - geohash算法原理及实现方式
- 转载和积累系列 - nodejs 获取IP地址
- 转载和积累系列 - linux 生成KEY的方法与使用
- 转载和积累系列 - 解决哈希(HASH)冲突的主要方法
- Grpc系列二 Grpc4种服务方法的定义和实现
- <转载>SpringMVC(7): 对Class.getResourceAsStream和ClassLoader.getResourceAsStream方法所使用的资源路径的解释