nodejs获取当前url和url参数值
//需要使用的模块 http url
当前url http://localhost:8888/select?aa=001&bb=002
var http = require('http');
var URL = require('url');
http.createServer(function(req, res){
var arg = url.parse(req.url).query; //方法一arg => aa=001&bb=002
var arg = url.parse(req.url, true).query; //方法二arg => { aa: '001', bb: '002' }
console.log(arg.aa);//返回001
console.log(arg.bb);//返回002
//然后就可以根据所得到的数据处理了
}).listen(8888);//建立服务器并监听端口
获取特定url参数值
var testUrl = 'http://localhost:8888/select?aa=001&bb=002';var p = URL.parse(testUrl); console.log(p.href); //取到的值是:http://localhost:8888/select?aa=001&bb=002console.log(p.protocol); //取到的值是:http: console.log( p.hostname);//取到的值是:locahostconsole.log(p.host);//取到的值是:localhost:8888console.log(p.port);//取到的值是:8888console.log(p.path);//取到的值是:/select?aa=001&bb=002console.log(p.hash);//取到的值是:null console.log(p.query);// 取到的值是:aa=001
在此值得注意的是当语句 是 var p = URL.parse(testUrl, true) 时,p.query则返回的是如:{aa:'001'}这样的对象, 直接打印p.query则返回 [object Object],这时我们可以这样 写: console.log(p.query.aa); //取到的值是:001console.log( p.pathname);//取到的值是:/select下面附上js的获取方法:
当前URL http://mj_0203.0fees.net/index.php?aa=001&bb=002
document.location: http://mj_0203.0fees.net/index.php?aa=001&bb=002
document.URL: http://mj_0203.0fees.net/index.php?aa=001&bb=002
document.location.href: http://mj_0203.0fees.net/index.php?aa=001&bb=002
self.location.href: http://mj_0203.0fees.net/index.php?aa=001&bb=002
top.location.href: http://mj_0203.0fees.net/index.php?aa=001&bb=002
parent.document.location: http://mj_0203.0fees.net/index.php?aa=001&bb=002
top.location.hostname: mj_0203.0fees.net
location.hostname: mj_0203.0fees.net
nodejs获取当前url和url参数值的更多相关文章
- .net获取当前网址url(各种参数值)
.net获取当前网址url(各种参数值) 假设当前页完整地址是:http://www.test.com/aaa/bbb.aspx?id=1&name=category" 先来看一下整 ...
- JS根据key值获取URL中的参数值,以及把URL的参数转换成json对象
//把url的参数部分转化成json对象 parseQueryString: function (url) { var reg_url = /^[^\?]+\?([\w\W]+)$/, reg_par ...
- 【javascript】js 获取 url 后的参数值
以前写过一篇类似的博文(提取 url 的搜索字符串中的参数),但是个人觉得使用起来不是很方便,今天抽空重新写了个函数,该函数代码更加简洁. //获取 url 后的参数值 function getUrl ...
- JQuery URL的GET参数值获取方法
// jQuery url get parameters function [获取URL的GET参数值] // <code> // var GET = $.urlGet(); //获取UR ...
- 在JQuery中获取URL中的参数值
添加一个js文件,代码如下 // * jQuery url get parameters function [获取URL的GET参数值] // *character_set UTF-8 // * au ...
- javascript获取URL参数和参数值
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jQuery获取URL的GET参数值
// jQuery url get parameters function [获取URL的GET参数值] // <code> // var GET = $.urlGet(); //获取UR ...
- 用Java和Nodejs获取http30X跳转后的url
用Java和Nodejs获取http30X跳转后的url 转 https://calfgz.github.io/blog/2018/05/http-redirect-java-node.html 30 ...
- [转]js获取域名、url、url参数值
//获取域名host1 = window.location.host;host2 = document.domain; //获取页面完整地址url = window.location.href; 获取 ...
随机推荐
- [荐]javascript Date format(js日期格式化)
cnblog:http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html 方法一: // 对Date的扩展,将 Date ...
- ado.net增删改查练习
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- Servlet域对象ServletContext小应用------计算网站访问量
package cn.yzu; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.Servlet ...
- Linux常用命令之安装VMware10中安装CentOS 6.4
笔者用过的Linux系统也就是现在主流的企业级linu系统RedHat跟CentOS,这边主要介绍下CentOS 6.4的安装 RedHat和CentOS差别不大,CentOS是一个基于RedHat ...
- file-max与ulimit的关系与差别
典型的,提供大量静态文件访问的web服务器,缓存服务器(如squid), 均要注意这个问题 网上的教程,大约只是简单说明了如何设置ulimit和file-max, 但并没有说清楚这两者之间的差别,让人 ...
- 关于C/C++中数组元素的初始化
1.一维数组初始化 对于一维数组,其初始化有一个错误的观点是:一直以为 int a[256]={0};是把a的所有元素初始化为0,int a[256]={1};是把a所有的元素初始化为1. 数组可 ...
- js 判断数组的值是否有重复
方法一: var s = ary.join(",")+","; for(var i=0;i<ary.length;i++) { if(s.replace( ...
- 移动网页 -- CSS布局
1.多栏结构 column-count column-width column:120px 3: column-gap:2em: column-rule:2px dotted gray: 跨越以及打断 ...
- hdu 1078 FatMouse and Cheese
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- Linux 环境中普通用户启动Myeclipse出错
将Myeclipse安装在/usr/local/myeclipse目录中,由root用户启动时没有问题,而用普通用户时出现如下故障: The configuration area at '/usr/l ...