Never use document.write as its outdated, the preferred way to add elements to DOM is using appendChild
Example Code for appending:
var textNode = document.createTextNode("some text"); // creates new text node
textNode.appendChild(document.body); // adds to the end of the body
For posting data to php by using jquery:
Before sending it to server, you need to format it as String using JSON.stringify
var formattedData = JSON.stringify(myJSONObject )
$.ajax({
type: "POST",
url: "server.php",
data: formattedData ,
dataType: 'json',
success: function () {
alert("Data posted to php and processed succesfully");
}
});