0
我需要从我的xml文件读取属性或节点。它与html页面位于同一台服务器上。使用ajax调用是错误的,还是应该使用更多本地js来提取数据?我需要访问Jquery中的数据以html形式动态输出它。我不会真的循环播放整个xml文件,我只想得到Picture的一个孩子。我知道在PHP我可以写: $ questions =(string)$ xml-> question [2];
作为一个例子,那会让我在我的XML文件中的第三个问题。我想知道相当于该行来获取jquery中的第二个元素。 在我的代码有用jquery读取xml元素
<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文件中的第二张照片的标题。
好的,我想,多亏。 eq代表什么? – james
@james它会根据您的要求从该元素集合中获取第二个元素。我刚刚在我的答案中添加了一个链接。只是阅读它供您参考。 –