首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

node.js 获取http url途径中的各个参数

2013-02-05 
node.js 获取http url路径中的各个参数若url为:http://localhost:8888/select?namea&id5http.createServ

node.js 获取http url路径中的各个参数

若url为:

    http://localhost:8888/select?name=a&id=5

http.createServer(function(request,response){        var pathname = url.parse(request.url).pathname;  //pathname => select        var arg = url.parse(request.url).query;          //arg => name=a&id=5        console.log("Request for " + arg );        var name = querystring.parse(arg).name;         //name => a        console.log("name = "+name);        console.log("Request for " + pathname + " received.");    }).listen(8888); 


//querystring.parse(arg)   => { name: 'a', id: '5' }


更多信息:   http://nodejs.org/api/url.html




热点排行