0

I have an html textbox and am entering double quotes in the text box.

E.g

I "a a person

I am using the Javsacript escape function and it encodes the quote to %22 which is correct

To the last point before hitting the server I have %22 but when I get it at the server by Request as follows:

Request["myJson"].Trim();

The %22 is converted back to "

Please help

2 Answers 2

1
  • You'd better not use escape, cause it is deprecated. Use similar function encodeURIComponent.
  • I don't know, what for do you need escaped string on the server, but if you really need it, just apply this function twice.
Sign up to request clarification or add additional context in comments.

5 Comments

It is being encoded properly but the problem is that when I get it on the server the value changes back to " rather than %21...is there anything else I can do
This is how parsing of GET/POST params is working for all servers. Apply this function twice: encodeURIComponent(encodeURIComponent(data))
Auto-decoding at servers happens cause of Content-encoding: application/x-www-form-urlencoded header of your request. You may change this behaviour by altering header as well.
Can you tell me how to change it back to I am " person on the server side using asp.net???
I suppose, with HttpContext.Current.Server.UrlDecode, but I'm not familiar with asp at all. In case of emergency google for asp UrlDecode ;-)
0

You can do all of the character escaping on the server-side if you want using HttpContext.Current.Server.UrlEncode(Request["myJson"].Trim());

1 Comment

but my Json is not a field ...it has many name value pairs...and I dont want to encode everything that is why I am sending it encoded from the client side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.