1

Ok guys, i've this:

<textarea class="boxCommento1" placeholder="Scrivi un commento.."></textarea>
<input style="width:100%;" type="button" value="Inserisci" onclick="functionThatObtainTextFromTextarea();"/>

When i click on the input button i get the text form the textarea, and i will insert that in my DB using PHP and AJAX, but there's a problem if i write something like this: "What did u do yesterday???" or char like this "&" when i'll get text using php, "?" and "&" won't be recognized of course, because using GET and POST "?" and "&" are used for php url variables... any advice???

PS: Sorry for my english.

Antony
  • 14,900
  • 10
  • 46
  • 74

1 Answers1

1

Use encodeURIComponent() in the AJAX Javascript.

When you get the variable in PHP with $_GET or $_REQUEST, it'll automatically be decoded, so you don't need to do anything else.

//Javascript
var inserisciValue = encodeURIComponent(theInsertisciValue);
Luke Shaheen
  • 4,262
  • 12
  • 52
  • 82