【发布时间】:2013-12-11 20:00:50
【问题描述】:
我需要从我的 xml 文件中读取属性或节点。它与 html 页面位于同一台服务器上。使用ajax调用是错误的还是应该使用更多的原生js来提取数据?我需要访问 Jquery 中的数据以在 html 中动态输出。我真的不会循环遍历整个 xml 文件,我想做的就是获取孩子的图片之一。我知道在 php 中我可以写:
$questions = (string)$xml->question[2];
作为一个例子,这将使我在我的 xml 文件中得到第三个问题。我想知道该行的等效项以获取 jquery 中的第二个元素。
在我的代码中,我有
<script language="JavaScript" type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "Pictures.xml",
datatype: "xml",
error: function(jqXHR, textStatus, errorThrown) {
console.log('Error: ' + errorThrown);
},
success: function(xml) {
console.log('AJAX Request is succeded.');
title =
$(xml).find('Picture')(1).find('title').text();//this line wont wrong
document.getElementById("picture").innerHTML = title;
}
});
});
</script>
所以任何人都可以帮我在 xml 文件中找到第二个图片标题的标题。
【问题讨论】: