I started with this post some time ago, unfortunately it didn't work. I decided to look in the console, an found out that it was not sending the requests' headers as they were unsafe. So I decided to comment them out for now.
However there is one more problem: "http is not defined". How do I solve that?
// will use this to turn an object into a url encoded string
var serializeObject = function(obj) {
var output = '';
for(var attr in obj) {
if(obj.hasOwnProperty(attr)) {
output += attr + '=' + obj + '&';
}
}
return output.slice(0, -1);
};
var url = 'http://spacej.ru/sample/getMcoordinates.php';
// you need to serialize your data into key value pairs like the following
var exampleCoords = {
x: 31,
y: 74,
z: 28
};
// postData will be x=10&y=20&z=30
var postData = serializeObject(exampleCoords);
var request = new XMLHttpRequest();
request.open('POST', url, true);
/*
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", postData.length);
request.setRequestHeader("Connection", "close");
*/
// this function gets called when the request changes
// mistake pops up here !
http.onreadystatechange = function() {
// request was successful
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(postData);