我的问题是我想从服务器返回一个xml文件返回给客户端,并使用jQuery的ajax函数解析它。这是代码:在jQuery中返回xml 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
和other.php
echo '<?xml version="1.0" encoding="utf-8"?>';
echo "<tables>";
echo "<doctor>Someone</doctor>";
echo "</tables>";
现在的作品完美。感谢您的快速回复!
是否$(XML).find( “医生”)工作吗? – 2011-05-18 23:20:02