how to encode a string in javascript 1

how to encode a string in javascript

var uri = "my test.asp?name=ståle&car=saab";
var res = encodeURI(uri); 

Here is what the above code is Doing:
1. The encodeURI() function encodes a URI by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two “surrogate” characters).
2. The encodeURIComponent() function encodes a URI component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two “surrogate” characters).
3. The decodeURI() function decodes a URI by replacing each escape sequence with the character that it represents. The escape sequences might be introduced by a function like encodeURI.
4. The decodeURIComponent() function decodes a URI component by replacing each escape sequence with the character that it represents. The escape sequences might be introduced by a function like encodeURIComponent.

Similar Posts