How to get GET (query string) variables in HTTP on Node.js? -


how can variables query string in node.js them in $_get/$_post in php?

here code, have passed parameters through xmlhttprequest. dont know how parameters. please give me suitable solution. want insert values in database.

server.js

var http = require('http'),     fs = require('fs'),     url = require('url');  var db = require('../db');  http.createserver(function(request, response){  var url = require('url'); var url_parts = url.parse(request.url, true); var query = url_parts.query;  console.log('name: ' + query.name);  }).listen(8001); 

index.hjs

function calling() {  xmlhttp = new xmlhttprequest(); xmlhttp.open("get","http://localhost:8001/name=user_name&cell=01234-1234567", true); xmlhttp.onreadystatechange=function(){      if (xmlhttp.readystate==4 && xmlhttp.status==200){        string=xmlhttp.responsetext;      } } xmlhttp.send(); } 

output

name: undefined 

looks request wrong url. should

http://localhost:8001/?name=user_name&cell=01234-1234567 

instead of

http://localhost:8001/name=user_name&cell=01234-1234567 

so name goes in query.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -