我正在尝试向数组的末尾添加一项,有点像数组列表。我尝试使用.push(),但我无法正确地从我的xml读取数据。如何“自动”更新jquery中的数组?(如果你想这样想,可以附加到它的末尾)
下面是我的jquery目前的样子。
images = new Array();
$.ajax({
type: "GET",
url: strXMLURL,
dataType: "xml",
success: function(xml) {
$(xml).find("image").each(function() {
images.push($(this).attr("src"));
});
},
error: function() {
alert("Error reading the XML");
}
});xml
<?xml version="1.0" encoding="utf-8" ?>
<gallery>
<image src="images/gallery/gallery1.jpg"/>
</gallery>如果你需要更多的信息,我很乐意提供更多。
发布于 2011-05-01 18:07:29
在ajax调用的成功函数中声明图像数组,以确保作用域保持正确,然后您的函数就可以工作了……
https://stackoverflow.com/questions/5838678
复制相似问题