This is the class of java scripts. I get the error of undefined for GetL() and its code doesn't run (I tried random consoles inside and they never get run). The first part of the function shows the array but GetL shows undefined.
What am I doing wrong?
function getC() {
var url = config.api.server + config.api.uri + "/c";
$.getJSON(url).done(function(r) {
if (!r.length) {
console.warn("Empty");
}
config.c = r;
console.log(r);
$.map(config.c, function(item) {
$("#c").append($('<option>').text(item.ci));
});
var a = $("#c").find("option:selected").text();
function GetL() {
var url = config.api.server + config.api.uri + "/l";
$.getJSON(url).done(function(answer) {
if (!answer.length) {
console.warn("Empty list");
}
config.l = answer;
console.log(answer);
r.forEach(function(cName) {
if (a == cName.ci) //check if name is equal to selection
{
var x = cName.ci.l; //get the ls of that name and put it in a place holder
console.log(x); //undefined
$.map(x, function(item) { //make a map to append those specific ls
$("#l").append($('<option>').text(item.str));
});
}
});
}).fail(function(data, status, error) {
console.error("Something went wrong");
});
}
GetL();
}).fail(function(data, status, error) {
console.error("Something went wrong");
});
} //end big function
GetLwould be undefined. What is the exact error message you get?GetLdoes not return anything to begin with. Furthermore,$.getJSONis asynchronous. I'm not totally sure what your expectation is.aor something else? (A shorter re-create that removes everything not needed to show the issue would make answering easier.)console.logthe arrayrat the begining of yourGetLfunction, and the itemcNamenextvar x = cName.ci.l;?