我有以下js。问题是,我无法访问 getMajorGroups 函数中的变量 jasonServiceUrlObject 。我已经在全局范围内声明了变量,但是当警报运行时,萤火虫会抛出未定义的错误!
var jsonServiceUrlObject = null;
function loadServiceXml(){
$.get("/xml/ServiceUrls.xml", function(xml){
jsonServiceUrlObject = $.xml2json(xml);
});
}
function getMajorGroups(){
var element = $(".item-group-button").first();
var serviceUrl = getServiceURL("getAllMajorGroups")
alert(jsonServiceUrlObject.service[1].service_key);
$.get(serviceUrl , function(data){
if(data.majorGroups.length != 0){
$('.panel_list').empty();
element.empty();
}
for(var i = 0; i < data.majorGroups.length; i++){
var clone = element.clone();
clone.append("<h3>" + data.majorGroups[i].description + "</h3>");
clone.attr("id", data.majorGroups[i].majorGroupId);
$('.panel_list').append(clone);
}
});
}