I have search textbox. When the user enters some text my querystring shows the text with ASCII characters like %20
and %3F
. I want to show this text in one of my textboxes without any ASCII codes like normal HTML text. How can I do this in Javascript?
By using the request's query using $request->getQuery() then $query->useUrlEncoding(false); you can disable UrlEncoding.
To remove a querystring from a url, use the split() method to split the string on a question mark and access the array element at index 0 , e.g. url. split('? ')[0] . The split method will return an array containing 2 substrings, where the first element is the url before the querystring.
Decoding in Javascript can be achieved using decodeURI function. It takes encodeURIComponent(url) string so it can decode these characters. 2. unescape() function: This function takes a string as a single parameter and uses it to decode that string encoded by the escape() function.
JavaScript encodeURI() The encodeURI() method encodes a URI.
Use decodeURIComponent()
:
var querystring = "?foo=bar%20baz";
console.log(decodeURIComponent(querystring));
decodeURIComponent MDN reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With