【发布时间】:2011-11-05 06:52:48
【问题描述】:
我希望这不是一个太新的问题,但我已经把头发拉出来有一段时间了,所以我想我会屈服并在这里寻求我的第一条建议。
我正在尝试使用 javascript / jQuery / ajax 读取外部 xml 文件,并将检索到的数据放入一个数组中,以便以后可以引用它。
到目前为止,我似乎一直在做所有事情,直到将数据放入数组中,但随后我很难在除创建它的函数内部之外的任何地方读取数据。为什么我无法从该函数以外的任何地方访问数组?
这是我的代码... 请帮忙!!
$.ajax({
type: "GET",
url: "data.xml",
dataType: "xml",
success: do_xmlParser
});
function do_xmlParser(xml)
{
var myArray = new Array();
$(xml).find("tag").each(function ()
{
myArray.push($(this).find("innerTag").text());
});
console.log("inside "+myArray); // This outputs the array I am expecting
return myArray; // is this right???
}
console.log("outside: "+myArray); // This does NOT output the array but instead I get "myArray is not defined"
【问题讨论】:
标签: javascript jquery xml ajax arrays