0
使用$.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>
這裏是我的這個例子說明:
- 當我點擊 '測試' 按鈕,它會調用AJAX展示PHP代碼
- 的結果在AJAX調用中,我只想顯示下面的2個
<div>
中的每個標記的文本(#show1
,#show2
)
上面的示例在$.ajax
中使用了dataType HTML,它適用於此類型。但是,當我嘗試使用dataType XML時,它沒有顯示任何內容。
所以,我希望你們給我一些關於這個問題的想法或參考。
耶!!,非常感謝。這是完美的工作:D。我忘記了xml ^^的結構 – Tristan 2011-05-31 03:28:16