1

I have my information appended in URL which follows a format of 2 query parameters and one encoded information. Is there any specific module to get the information from the query parameters or I may have to use split functions ? Sample : ?xys=2929292&abc=1213123&%5B%7B%22fm%22%3A%2212%22%2C%22id%22%3A%22as-as%22%2C%22pf%22%3A%7B%22nm%22%3A%22cc%22%7D%2C%22tx%22%3A%7B%22bd%22%3A%22Hi%22%7D%2C%22ts%22%3A%221211%22%2C%22ty%22%3A%22tx%22%2C%22wanm%22%3A%2212123%22%7D%5D

I am trying for node server

Sample : ?xys=2929292&abc=1213123&%5B%7B%22fm%22%3A%2212%22%2C%22id%22%3A%22as-as%22%2C%22pf%22%3A%7B%22nm%22%3A%22cc%22%7D%2C%22tx%22%3A%7B%22bd%22%3A%22Hi%22%7D%2C%22ts%22%3A%221211%22%2C%22ty%22%3A%22tx%22%2C%22wanm%22%3A%2212123%22%7D%5D

Expected Output xys = 2929292 abc = 1213123 message = [{"fm":"12","id":"as-as","pf":{"nm":"cc"},"tx":{"bd":"Hi"},"ts":"1211","ty":"tx","wanm":"12123"}]

3 Answers3

1

Try The Vanila JS. Like Below

document.location.search
Dev Matee
  • 5,525
  • 2
  • 27
  • 33
0

install query-string package from here and work using it e.g.

var const qS = require('query-string');


const parsed = qS.parse(location.search);
console.log(parsed);
Satya
  • 8,693
  • 5
  • 34
  • 55
0

First of all your query is wrong, it should be

?xys=2929292&abc=1213123&message=%5B%7B%22fm%22%3A%2212%22%2C%22id%22%3A%22as-as%22%2C%22pf%22%3A%7B%22nm%22%3A%22cc%22%7D%2C%22tx%22%3A%7B%22bd%22%3A%22Hi%22%7D%2C%22ts%22%3A%221211%22%2C%22ty%22%3A%22tx%22%2C%22wanm%22%3A%2212123%22%7D%5D

rest of the answer is assuming you are using node server with express

then in node server you can get output from

console.log(req.query);
xys = parseFloat(req.query.xys) //remove parseFloat if you want string
abc = parseFloat(req.query.abc)
message = JSON.parse(req.query.message) //JSON.parse() will convert string to array
Vinil Prabhu
  • 1,279
  • 1
  • 10
  • 22