Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove URL encoding in my querystring using Javascript

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?

like image 806
Suresh Ponnukalai Avatar asked Jun 13 '14 13:06

Suresh Ponnukalai


People also ask

How do I disable URL Encoding?

By using the request's query using $request->getQuery() then $query->useUrlEncoding(false); you can disable UrlEncoding.

How do I remove Querystring from URL?

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.

How do you decode or encode a URL in JavaScript?

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.

Which function is used in JavaScript for URL Encoding?

JavaScript encodeURI() The encodeURI() method encodes a URI.


1 Answers

Use decodeURIComponent():

var querystring = "?foo=bar%20baz";
console.log(decodeURIComponent(querystring));

decodeURIComponent MDN reference

like image 69
Rory McCrossan Avatar answered Sep 21 '22 15:09

Rory McCrossan