I have my javascript here on checkTests.php
, which is a function as follows
function confirmedUpload(){
//Make the button so it can't be clicked again
document.getElementById('confirmUpload').setAttribute("disabled", true);
//This is the data we are posting
var postData = JSON.stringify(<?php echo $uploadJSON; ?>);
//This bit works OK and I see the string of JSON printed in the console.
console.log(postData);
//Create an XMLHttpRequestObject
var xhr = new XMLHttpRequest();
xhr.open("POST", "/uploadTests.php", true);
xhr.setRequestHeader( "Content-Type", "application/json" );
xhr.send(postData);
//Wait for the page to respond.
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4 && xhr.status == 200)
{
console.log(this.responseText);
}
}
}
which I would expect to post the data postData
to the page uploadTests.php
and then return the array(data)
from the uploadTests.php
page in the console.
But what actually happens is that the post request is made, I see the output console.log(postData);
from the javascript, but then when uploadTests.php
returns the value, all I get is array() 0
and there's no data.
contents of uploadTests.php
is:
<?php
print_r($_POST);
echo ' ' . sizeof($_POST);
?>
why does uploadTests.php
think that the $_POST was blank?