Escape-unescape single quote & other characters in client-server communication

Escape in JQuery
var str = escape(txt.val());

Unescape  in Server
HttpUtility.UrlDecode(str);

Unescape in JQuery
var regionName = unescape(row.RegionName);
Do not use HttpUtility.UrlEncode and HttpUtility.UrlDecode on cookie keys or values.HttpUtility.UrlEncode will improperly escape space characters to '+' and lower case every escape sequence. HttpUtility.UrlDecode will improperly unescape every '+' to a space character. Instead, use System.Uri.EscapeDataString and System.Uri.UnescapeDataString.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s