I am trying to see the json data I sent to the server using XMLHttpRequest but it seems that the server is not receiving it, when I run the javascript the alert window will pop up but doesn't print anything. Anyone know how to solve this problem? Thanks
On the client side, Java script
var obj = {"action": "nothing"};
var jsonString = "jsonString=" + JSON.stringify(obj);
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST","http://myserver/main.php",true);
xmlhttp.setRequestHeader("Content-type","application/json");
xmlhttp.setRequestHeader("Content-Length",jsonString.length);
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState === 4 && xmlhttp.status === 200){
alert(xmlhttp.responseText);
}
}
xmlhttp.send(jsonString);
On the server,php
if(isset($_POST['jsonString']))
echo $_POST['jsonString'];