【发布时间】:2011-05-31 02:05:11
【问题描述】:
在使用$.ajax 时,我在使用 XML 数据类型时遇到了一些困难。
我创建了一个 PHP 文件 (test.php):
<script type="text/javascript" src="js/jquery.min.js"></script>
<?php
//this code will show some xml tag when there is an ajax call
if(isset($_REQUEST['t']) && $_REQUEST['t']==1){
echo "<result >";
echo "<info>Tristan Jun</info>";
echo "<age>22</age>";
echo "</result>";
return;
}
?>
<script>
$(document).ready(function(){
$('#testing').click(function(){
alert('uuuuuuu');
var content = $.ajax({
type:"GET",
url :"test.php",
data:'t=1',
dataType:"**html**",
async:false,
success:function(content){
cont = $(content);
inf = cont.find('info').text();
age = cont.find('agel').text();
//alert('inf');
$('#show1').html(inf);
$('#show2').html(total);
},
error: function(){
alert('THERE'S AN ERROR');
}
}).**responseHTML**;
});//end of click
});//end of ready
</script>
<a id="testing" href="#">TEST</a>
<div id="show1"></div>
<div id="show2" style="background-color:#069"></div>
这是我对这个例子的描述:
- 当我点击“TEST”按钮时,它会调用 AJAX 来显示 PHP 代码的结果
- 在 AJAX 调用中,我只想在下面的 2 个
<div>中显示每个标签的文本(#show1,#show2)
上面的示例在$.ajax 中使用了 dataType HTML,它适用于这种类型。但是当我尝试使用 dataType XML 时,它没有显示任何内容。
所以,我希望你们给我一些想法或一些关于这个问题的参考。
【问题讨论】: