1

I changed an XMLDocument localy using javascript. How do I save it on the server? I tried the following:

if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
}
else{ // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","./path/to/phpfile/file.php?newdocument="+newxmldocument,true);
xmlhttp.send();

In the php-file I wanted to do something like this:

$file = "./path/to/xmlfile/xmlfile.xml";
$dom = new DOMDocument();
$dom = $_REQUEST['newdocument'];
$dom->save($file);

This does not work, however.

Is there an easy way to save the XMLDocument object the php-file recieves?

Urinprobe
  • 97
  • 1
  • 11

1 Answers1

1

You should try sending the XMLDocument with a POST as a multipart.

Cucu
  • 185
  • 12
  • Do you mean using "POST" instead of "GET"? – Urinprobe Jun 11 '14 at 10:34
  • Yes! Please read about the limitations of GET method and POST method. http://stackoverflow.com/questions/266322/is-there-a-limit-to-the-length-of-a-get-request – Cucu Jun 11 '14 at 10:42
  • Ok, so I changed that to POST, put the data into the send method, and changed the php-file to use POST, too. Setting $dom=$admin returns an fatal error, though, when using $dom->save($file), namely "Call to a member function save() on a non-object". – Urinprobe Jun 11 '14 at 10:55
  • I also added this: xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); – Urinprobe Jun 11 '14 at 10:57
  • add a var_dump to the php file. Post here what it prints. – Cucu Jun 11 '14 at 12:23
  • The output of var_dump simply is "string(20) "[object XMLDocument]"" – Urinprobe Jun 12 '14 at 07:20
  • could the error be in the javascript part? If so, I'll update the question to represent what is done there... – Urinprobe Jun 12 '14 at 07:22
  • I solved the problem. I ended up converting the xml-object to a string with XMLSerializer in javascript and using ->loadXML in php. Thank you for your help, it was exactly the input that I needed :) – Urinprobe Jun 12 '14 at 10:33
  • glad to help! Now please post the final solution so that others can find it easily. Cheers! – Cucu Jun 12 '14 at 13:44