How do I parse XML from PHP that was sent to the server as text/xml?

旧巷老猫 提交于 2019-12-19 04:39:44

问题


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.


回答1:


I think you want something like:

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


来源:https://stackoverflow.com/questions/948610/how-do-i-parse-xml-from-php-that-was-sent-to-the-server-as-text-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!