简体   繁体   English

从jQuery AJAX请求中检索PHP中的XML

[英]Retrieve XML in PHP from jQuery AJAX Request

I make jQuery Ajax request which return output in XML format. 我发出jQuery Ajax请求,该请求以XML格式返回输出。 i want to access this XML in PHP to Process on data. 我想在PHP访问此XML以处理数据。 Below is sample of my code... 以下是我的代码示例...

getTime.php File getTime.php文件

<?php
    header("Content-type: text/xml");

    echo '<Dates>';

    echo '<Now ';
    echo 'val="' . date("h:m:s") . '" ';
    echo '/>';

    echo '</Dates>';
    //echo date("h:m:s");
?>

index.php File index.php文件

jQuery(document).ready(function(e) {
    $('#btnTime').click(function(){
        getData("GetTime.php");
    });
});
function getData(strUrl)
{
    $.ajax({
        type: "POST",
        url: strUrl,
        dataType: "xml",
        success: function(output){
                    // I want to Retrieve this XML Object (output) to PHP
        }
    });
}

How can I access XML outputed by jQuery in PHP ? 如何在PHP访问jQuery输出的XML? Please help me.. 请帮我..

You need to make another call to your webserver in the success callback. 您需要在成功回调中再次调用Web服务器。


function getData(strUrl)
{
    $.ajax({
        type: "POST",
        url: strUrl,
        dataType: "xml",
        success: function(output){
            $.ajax({
                type: "POST",
                url: strUrlToPostXml,
                dataType: "xml",
                success: function(output){
                    // Whatever you want, the Xml has been successfully posted back to Php
                }
            });
        }
    });
}

But it's quite weird to do that though: it would be much better to have everything done on the server side using the initial call. 但这确实很奇怪:使用初始调用在服务器端完成所有操作会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM