在jquery ajax中返回xml

Chr*_*sis 6 xml ajax jquery types return

我的问题是我想将一个xml文件从服务器返回给客户端并使用jquery的jjax函数解析它.这是代码:

客户:

$("#submit").click(function(){          
    $.ajax({  
        type: "POST",  
        url: "search.php",  
        data: "whatever",
        dataType: "xml",
        async: false,
        success: function(xml){
            var data = $('doctor',xml).text();
            alert(data);
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

服务器(php文件),

header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="utf-8"?>';
echo "<tables>";
echo "<doctor>Someone</doctor>";
echo "</tables>";
Run Code Online (Sandbox Code Playgroud)

我有一个空白的警报,我不知道为什么?


好的我找到了.我的php文件是这种形式

//some code
include("other.php");
//some other code
Run Code Online (Sandbox Code Playgroud)

other.php文件是我上面发布的文件.我剪切/粘贴标题,以便最终的php文件

//some code
header('Content-type: text/xml');
include("other.php");
//some other code
Run Code Online (Sandbox Code Playgroud)

和其他.php

echo '<?xml version="1.0" encoding="utf-8"?>';
echo "<tables>";
echo "<doctor>Someone</doctor>";
echo "</tables>";
Run Code Online (Sandbox Code Playgroud)

现在它完美无缺.谢谢你的快速回复!

Kev*_*nis 1

尝试这个:var data = $(xml).find('doctor').text()

在您的示例中,“xml”不是 jQuery 对象。