I'm trying to pass somewhat large data sets over to PHP via an AJAX POST. My data is being truncated, but I can't see why.
var greeting = tinyMCE.get("greeting").getContent();
...
var content = "subject=" +subject+
"&greeting=" +greeting+
"&results=" +results+
"&upcoming=" +upcoming+
"&thisweek=" +thisweek+
"&signoff=" +signoff;
console.log(content); //<--see below for this output
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "scripts/send_email.php", true);
xmlhttp.setRequestHeader("content-type", "application/x-www-form-urlencoded");
xmlhttp.send(content);
send_email.php
$greeting = $_POST['greeting'];
echo $greeting;
die();
This is the console output for my content variable (note that where you see formatting, the console output the HTML tag, but I don't know how to display the tag here.)
> subject=test&greeting=<p class="p1"><strong>Hello all,</strong></p> <p
> class="p2"> </p> <p class="p1"> </p> <p class="p3">This is a
> test. I am just typing some random stuff to verify that all of my data
> is getting passed correctly over to PHP. However, it seems that this
> data is being truncated for reasons that I cannot explain. Why would
> this happen. How can I get all of this data to pass correctly? It
> doesn’t make any sense to me as I am using an AJAX POST call and
> not a GET call, so my data length should not be arbitrarily
> limited.</p>&results=<p><strong><span style="text-decoration:
> underline;">RESULTS</span></strong><br /><br /><br
> /></p>&upcoming=<p><strong><span style="text-decoration:
> underline;">UPCOMING EVENTS</span></strong><br /><br /><br
> /></p>&thisweek=<p><strong><span style="text-decoration:
> underline;">THIS WEEK</span></strong><br /><br /><br
> /></p>&signoff=<p>See you out there.</p>"
But, my php echo statement outputs only this:
Hello all,
which clearly truncates the rest of the data that I am trying to pas over. Why? What am I doing wrong? Thank you!
You need to encode the data, which you put in parameters
var content = "subject=" + encodeURIComponent(subject) +
etc.
You just echo your greeting.
try this:
echo implode($_POST);
You're sending with a content type of "... url-encoded" while sending data not url encoded. You need to encode your data correctly before sending it (encodeURIComponent etc)