Michael Kiselev Michael Kiselev - 1 month ago 8
Javascript Question

Convert ascii character codes into letters in a string containing text and ascii codes in JS

I am working on an HTML web page, and in the js, I read the end of the URL and place it in a div e.g. if the URL is

http://example.com/file.html?postval=Hello, world!


it should post "Hello, world!", unfortunately, it posts "Hello,%20world". how can I fix this?

Answer

Use decodeURIComponent

var a = decodeURIComponent('Hello,%20world');

a = 'Hello, world!';