0

我发出 jQueryAjax请求,它以XML格式返回输出。我想访问它XMLPHP处理数据。以下是我的代码示例...

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 文件

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
        }
    });
}

如何访问 jQuery 中输出的 XML PHP?请帮我..

4

1 回答 1

1

您需要在成功回调中再次调用您的网络服务器。


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
                }
            });
        }
    });
}

但是这样做很奇怪:使用初始调用在服务器端完成所有事情会更好。

于 2013-09-07T11:47:41.400 回答