【发布时间】:2011-08-28 11:14:37
【问题描述】:
我的问题是我想将一个 xml 文件从服务器返回给客户端,并使用 jquery 的 ajax 函数对其进行解析。这是代码:
客户:
$("#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);
}
});
});
服务器(php 文件),
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="utf-8"?>';
echo "<tables>";
echo "<doctor>Someone</doctor>";
echo "</tables>";
我有一个空白警报,我不知道为什么??
好的,我找到了。我的 php 文件是这种形式
//some code
include("other.php");
//some other code
other.php 文件是我在上面发布的文件。我剪切/粘贴标题,所以最终的 php 文件将是
//some code
header('Content-type: text/xml');
include("other.php");
//some other code
和其他.php
echo '<?xml version="1.0" encoding="utf-8"?>';
echo "<tables>";
echo "<doctor>Someone</doctor>";
echo "</tables>";
现在它完美运行。感谢您的快速回复!
【问题讨论】:
-
$(xml).find("doctor") 有用吗?
标签: jquery xml ajax types return