tags:

views:

60

answers:

4

I noticed that certain characters entered in text box and sent through Jquery Ajax request as parms are being mis-interpretted. (at least from my point of view). The "&" creates a new unwanted parm. The "+" disappears entirely.

I want to get value of text box and convert to html entities. Something like this I think:

SafeParm = $("#myDIV").val().html();

Any other recommendations for making for making safe ajax calls with jQuery are welcome.

+1  A: 

use want the escape function:

SafeParm = escape($("#myDIV").val().html());
GSto
escape will not properly encode "+". See http://xkr.us/articles/javascript/encode-compare/
noah
A: 

You have to encode the parameters passed to a request.

See Encoding html using javascript's escape & unescape

You can escape $("#myDIV").val() where myDiv is the id of your textbox.

rahul
+2  A: 

In this case, encodeURIComponent is what you want. There are weird edge cases where escape may not do exactly what you want it to. See: http://xkr.us/articles/javascript/encode-compare/

noah
A: 

escape is deprecated. Use encodeURI and encodeURIComponent.

atxryan