Wednesday 15 February 2012

javascript - escaping double quotes in text field -


I have a JSP page which is populated with some textures and the submit button that makes an AJAX GET request. Users can type in any text. I am having problems when the user enters the string with double quoted string or backslash. I am currently using encoded RIMPonent and JSON.stringify so that the request URL parameters can be prepared. Is this the proper way? The backend code is getting an improper Jason object. Here is a sample

User type: Test "cases" good in txtArea0

js code:

  var txtData0 = Encoderic Silence ($ ('# txtArea0'). Val ()); Var txtData1 = encodeurIComponent ($ ('# txtArea1'). Val ()); Var msg = JSON.stringify ([{"id": 0, "txtData": txtData0}, ...]);   

However, my server receives the message "[{id": 0, "txtData": msg "msg" receives "" good "}, ... ] " I do not completely know why this is happening.

I am currently using encodeuric components and JSON.stringify < / Blockquote>

This is your problem.
You can actually survive only when you are actually making strings in that format.

Since you do not want to add values ​​to any URL, you should not call encodercontact .

If you include Jasonson in the URL, you will need to call EncoderIconconverter , but no one else.

In summary

Escape methods are not a magic sauce that your code works.

You need to avoid right at the right time.

No comments:

Post a Comment