job.answiz.com
  • 1
Votes
name
name Punditsdkoslkdosdkoskdo

How to escaping ampersand in url

I am trying to send a GET message that contains strings with ampersands and can't figure how to escape the ampersand in the url.

Example:

http://www.example.com?candy_name=M&M
result => candy_name = M

I also tried:

http://www.example.com?candy_name=M&M
result => candy_name = M\

I am using urls manually so I just need the correct characters.

I can't use any libraries. How can it be done?

They need to be percent-encoded:

> encodeURIComponent('&')
"%26"

So in your case, the URL would look like:

http://www.mysite.com?candy_name=M%26M
  • 1
Reply Report