1

I have a client-side script written in jQuery that is sending text/xml data to the server, but I can't figure out how to parse the request since the data is not a query string variable. The jQuery looks like this:

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

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

  • 2
    What does print_r($_POST) look like? – Ryan Schumacher Jun 04 '09 at 04:46
  • Yeah, that was part of the issue. I was trying that, and it was just returning an empty array(), so I kept thinking it was a problem with the jQuery and not the PHP. However, with Matthew's code below, a print_r() is still blank, but a var_dump() shows the object nodes. –  Jun 04 '09 at 11:05

1 Answers1

3

I think you want something like:

$xml_text = file_get_contents("php://input");
$xml = simplexml_load_string($xml_text);
Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539