Making secure ajax calls with jQuery

I noticed that some characters are entered into the text field and sent via the jQuery Ajax request since the parfut is not interpreted correctly. (at least from my point of view). "&" creates new unwanted parm. "+" Completely disappears.

I want to get the value of a text field and convert it to html objects. Something like this I think:

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

Any other recommendations on making secure ajax calls using jQuery are welcome.

+3
source share
4 answers

use the escape function:

SafeParm = escape($("#myDIV").val().html());
+2
source

You need to encode the parameters passed to the request.

See html coding with javascript escape and unescape

You can avoid $("#myDIV").val()where myDiv is the identifier of your text field.

0
source

escapeoutdated. Use encodeURIand encodeURIComponent.

0
source

Source: https://habr.com/ru/post/1728328/


All Articles