I've been at this for hours and have yet to find a solution. Chrome's network activity shows that the post is being sent and the payload is "id=a1" but the php always returns an empty string. Either this is some silly typo that I've missed for the longest time, or my server host php.ini is blocking it. I contemplated the later, but I've used plenty of post scripts previously on this host without issue.
I've tried every combination I could think of with no avail :(
What could be causing this?
relevant .js:
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open("POST", "api.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www/form-urlencoded");
xhr.send("id=" + "a1");
xhr.onreadystatechange = display_data;
function display_data() {
if (xhr.readyState == 4 && xhr.status == 200) {
alert(xhr.responseText);
}
}
relevant .php:
$id = $_POST['id'];
echo $id;
xhr.send("id=" + "a1");your last line of code and try againapplication/x-www/form-urlencoded, you needapplication/x-www-form-urlencoded. Making this change alters the output from an error message mentioning an undefined index, 'id', toa1