0 votes
in Education by (1.7m points)
I'm sending HTML trough POST and the '&'s are messing it up, how can I avoid it? Tried replacing & with \&, didn't work.

For more info: I'm trying to use email templates in an in-house project and stuff like &nbsp is screwing up the POST i'm using to send them from javascript to php.

code below:

emailcontinut = CKEDITOR.instances['emailContinut'].getData();

var parametri = "Trimite="+trimite + "&codc="+codc + "&emailSubiect="+emailsubiect + "&emailContinut="+emailcontinut + "&adact="+adact + "&sid="+Math.random();

xmlhttp_email_actiune.open("POST",url,true);

xmlhttp_email_actiune.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlhttp_email_actiune.setRequestHeader("Content-length", parametri.length);

xmlhttp_email_actiune.setRequestHeader("Connection", "close");

xmlhttp_email_actiune.send(parametri);

when I echo $_POST['emailContinut'] in the target PHP, it stops at the first '&' in an &nbsp

the solution was just

emailcontinut =  escape(emailcontinut);

in javascript and then using stripslashes() in php to decode it. thanks.

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by (1.7m points)
You need to URL-encode and/or HTML-encode your content, depending on what you're actually doing.
...