I was wondering if I could send some data from my client-side (2d application using HTML5’s canvas) to the server-side in the XML format?
I tried something like this:
function send_xml_data_to_server(xml, url) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(xml);
xmlhttp.onreadystatechange = function() {
callback_response_from_server(xmlhttp);
}
}
Because in the informations that I must send to the server-side, it contains a few texts and it doesn’t seem to work quite right with the the MIME:
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
But when I’m on the server-side I checked $_POST but there is nothing inside it, the same for $_REQUEST.
So, at the end, I was wondering if it is even possible to send XML data to the server-side PHP using XMLHttpRequest?
Thanks!
There’s nothing wrong on the client side, but
$_POSTcontains a parsed set of key/value pairs, but that’s not what you’re sending to the server. Use something like this:Then you can parse the string using SimpleXML or whatever you like.