取当前的地址栏的Url和url中的参数
看到这样一段代码:
exports.showLogin = function (req, res) {
req.session._loginReferer = req.headers.referer;
res.render('sign/signin');
};
php中可以通过post or get 获取到url中的参数值,最近接触了node那么在nodejs里是怎么做的呢,上代码了!
//需要使用的模块 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
取当前的地址栏的Url和url中的参数的更多相关文章
- Django(命名URL和URL反向解析)
day67 参考: https://www.cnblogs.com/liwenzhou/articles/8271147.html#autoid-1-4-0 反向解析URL 本 ...
- C# 获取地址栏的地址(URL)
原文地址:http://blog.csdn.net/dingxingmei/article/details/8448009 设当前页完整地址是:http://www.jb51.net/aaa/bbb. ...
- js获取当前地址栏的域名、Url、相对路径和参数以及指定参数
以下代码整理于网络 1.设置或获取对象指定的文件名或路径. window.location.pathname 例:http://localhost:8086/topic/index?topicId=3 ...
- JavaScript------获取url地址中的参数
$(document).ready(function () { //获取地址中的参数(name是字符串) function getParameter(name) { //正则表达式 var reg = ...
- getQueryString----获取url中得参数
/** * 获取url中得参数 * @param name * @returns {null} */ window.getQueryString = function (name) { var reg ...
- jQuery获取URL中的参数
//获取URL地址栏中的参数 function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + &quo ...
- js获取当前域名、Url、相对路径和参数以及指定参数
一.js获取当前域名有2种方法 1.方法一 var domain = document.domain; 2.方法二 var domain = window.location.host; 3.注意问题 ...
- js获取URL中的参数
js获取URL中的一些参数的意思 location对象 含有当前URL的信息. 属性 href 整个URL字符串. protocol 含有URL第一部分的字符串,如http: host 包含有URL中 ...
- nodejs获取当前url和url参数值
//需要使用的模块 http url 当前url http://localhost:8888/select?aa=001&bb=002 var http = require('http ...
随机推荐
- 续Gulp使用入门-综合运用>使用Gulp构建一个项目
这是我的文件目录结构图 下面是我gulpfile.js的配置 'use strict' var gulp=require('gulp'); var gutil=require('gulp-util' ...
- java加密算法--MD5加密和哈希散列带秘钥加密算法源码
package com.ompa.common.utils; import java.security.MessageDigest; import java.security.NoSuchAlgori ...
- OFFICE2013实现选中单元格所在行、列高亮显示
在你要实现此功能的工作表标签右击,在弹出的菜单中选择编辑代码,然后输入下面代码保存即可! 如没有出现效果,则可能是禁用了宏的关系.所以要在安全选项中启用宏选项. Private Sub Workshe ...
- linux搭建一个配置简单的nginx反向代理服务器 2个tomcat
1.我们只要实现访问nginx服务器能跳转到不同的服务器即可,我本地测试是这样的, 在nginx服务器里面搭建了2个tomcat,2个tomcat端口分别是8080和8081,当我输入我nginx服务 ...
- nginx看端口使用情况
[root@iZ94j7ahvuvZ sbin]# netstat -apn Active Internet connections (servers and established) Proto R ...
- linux搭建mysql 5.6.28
1.下载rmp文件 http://dev.mysql.com/downloads/mysql/ 2.安装 rpm -ivh MySQL-server--.linux_glibc2..x86_64.rp ...
- Hadoop 分布式文件系统 - HDFS
当数据集超过一个单独的物理计算机的存储能力时,便有必要将它分不到多个独立的计算机上.管理着跨计算机网络存储的文件系统称为分布式文件系统.Hadoop 的分布式文件系统称为 HDFS,它 是为 以流式数 ...
- 自定义input[type="file"]的样式
input[type="file"]的样式在各个浏览器中的表现不尽相同: 1. chrome: 2. firefox: 3. opera: 4. ie: 5. edge: 另外,当 ...
- 谷歌开源项目Google Preview Image Extractor(PIEX) (附上完整demo代码)
前天偶然看到谷歌开源项目中有一个近乎无人问津的项目Google Preview Image Extractor(PIEX) . 项目地址: https://github.com/google/piex ...
- readonly与const
readonly与const 在C#中,readonly 与 const 都是定义常量,但不同之处在于:readonly 是运行时常量,而 const 是编译时常量. ; public void Te ...