nodejs url with hash

Rax*_*eth 7 node.js

url=require('url');

qs=require('querystring');

var http=require('http');

http.createServer(server).listen(1337, 'hostname');

function server(req, res) {

  res.writeHead(200, {'Content-Type': 'text/plain'});

  res.write(req.url);

  a=url.parse(req.url, true);

  console.log(a);

  res.end('\nHello World\n');

}

console.log('Server running at http://127.0.0.1:1337/');




//http://host:1337/#A=1111111 <--- not coming in log or url
//http://host:1337/?A=11111111 <--- works ok

//usecase : facebook access_token url format is something similar to above
Run Code Online (Sandbox Code Playgroud)

log*_*yth 20

'#'标记之后的URL部分(称为fragment)不会发送到服务器.如果将数据存储在片段中,则由您来处理该数据并使用GET参数中的数据执行ajax请求.

  • Facebook使用http:// servername:port/path#access_token = somestring以该格式回调dev服务器 (2认同)