1

In my application I have a list of registered products.

I am trying to send the product name in the url.

However the product name it has # hashtag and the product name is arriving incomplete on the server:

front end

var product = "PLASTIC #1JQ-M 1CV T-PLAS"
return this._http.get(Config.URL_SITE + 'list/productLen?product='+product)...

back end

router.get('/productLen', function(req, res, next) {
  var productName= req.query.product;
  console.log(productName) //PLASTIC
...

How to make the productName variable receive the full name? "PLASTIC #1JQ-M 1CV T-PLAS"

rafaelcb21
  • 12,422
  • 28
  • 62
  • 86

1 Answers1

5

You should use encodeURIComponent() function before adding product name to URL.

var product = "PLASTIC #1JQ-M 1CV T-PLAS"
return this._http.get(Config.URL_SITE + 'list/productLen?product=' + encodeURIComponent(product))...

Everything after hash is stripped off by the browser Why the hash part of the URL is not in the server side?.

There are alternative solutions: How to get Url Hash (#) from server side, but they are mostly how to retrieve hash on server in general.

Community
  • 1
  • 1
Andrii Litvinov
  • 12,402
  • 3
  • 52
  • 59