I am trying to run this:
function loadApp() {
var content = getContent("content.xml");
createMap(content);
}
function getContent(file) {
$.ajax({
type: "GET",
url: file,
dataType: "xml",
success: parseXml
});
function parseXml(xml) {
var content = [];
$("element", xml).each(function () {
var var1 = $(this).children("var1").text(),
content.push(var1)
});
return content;
}
}
function createMap(content) {
alert(content);
}
But when I open the page the alert says my content variable is undefined. getContent() works fine and gives content a string value when I delete createMap(content); from loadApp(). It seems that createMap() is running before getContent() and that is why the variable is not defined yet, any idea why this happens and how can I solve it?
Thanks in advance.
getContentfunction does an asynchronous action (like an Ajax request)...