I've looked and looked but nothing quite touches this question.
I'm trying to send an XMLHttpRequest
via JavaScript* in Chrome. Here is my page:
<!DOCTYPE html>
<html>
<head>
<title>ROAM</title>
<script>
function post_something() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', "post_test.php", true);
xmlhttp.setRequestHeader('Content-Type', 'text/plain');
xmlhttp.send("This is my text.");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
console.log(xmlhttp.responseText);
}
}
}
</script>
</head>
<body>
<table>
<tr><td><input type="button" value="POST a thingy"
onclick="javascript:post_something()">
</input>
</td></tr>
</table>
</body>
</html>
Here is my PHP:
<?php
print_r($_POST);
/>
This shows up in the console:
Array
(
)
If something somewhere would just tell me what XMLHttpRequest.send actually does under the hood, what exactly it sends, how PHP parses it, and what PHP expects, I could solve this dumb thing myself.
*Please understand I don't want to use a form or jQuery. I want to work with an XMLHttpRequest object directly until I understand exactly how it works and how PHP receives and parses it.