Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape "&" ampersand character in form input using jQuery

I have a problem with my jQuery script that send data via POST method. The problem is whenever it sends data via Ajax that has an "&" ampersand in the sentence, it will cut the sentence when found "&".

Please check the images below for more info.

The text that pass to ajax POSTOutput after ajax POST on firebugData that has been save in the databaseThe jQuery ajax POST

like image 838
jameserie Avatar asked Feb 16 '11 18:02

jameserie


People also ask

Can we escape the reality?

While we may not be able to jump on the next plane to an island-getaway, we all can escape from reality mentally. Because every mind is different, it may take some trial and error to find out how you best are able to mentally escape reality.

What does it mean to mentally escape?

Escapism is mental diversion from unpleasant or boring aspects of daily life, typically through activities involving imagination or entertainment. Escapism may be used to occupy one's self away from persistent feelings of depression or general sadness.


1 Answers

htmlentites

This function is identical to htmlspecialchars() in all ways, except with htmlentites(), all characters which have HTML character entity equivalents are translated into these entities.

If you're wanting to decode instead (the reverse) you can use html_entity_decode().

Example:

echo htmlentities("&"); // &

if your directly doing this in the browser you should be able to use:

encodeURIComponent(string input);

Example:

encodeURIComponent($.trim($("input[name=t-tim_rendered-"+id+"]").val().toString()));
like image 96
RobertPitt Avatar answered Oct 05 '22 14:10

RobertPitt