How to process XML with PHP that was sent to the server as text / xml?

I have a client side script written in jQuery that sends text / XML data to the server, but I cannot figure out how to parse the request since the data is not a query string. JQuery looks like this:

jQuery.ajax({ url: "test.php", type: "POST", processData: false, contentType: "text/xml", data: xmlDoc, success: function( data ) { alert( data ); } }); 

xmlDoc is a valid XML document. I tried everything in PHP, but I can not get any of the nodes or content using simplexml.

+1
source share
1 answer

I think you need something like:

 $xml_text = file_get_contents("php://input"); $xml = simplexml_load_string($xml_text); 
+3
source

All Articles