I have a function that does a foreach loop in a list of views and needs to send an AJAX request for each view in the loop. When it gets the results in the success function, it checked if a specific Id is returned and, if it is, adds this view to a selectBox. The problem is that when I tried to define the .change event on the selectBox it gave me an error as no option have been added. I have thought about adding ajaxStop, but I have other different AJAX request. Does anybody knows how could i wait till those Ajax request have been finished, but no others?
var newdiv = $('<div id="viewListDiv" style ="margin:auto" ></div> ')
var selectBox = $('<select id = "ViewsList" class="form-control" style="width:250px;margin-left: 70px; margin-rigth:70px;" ></select>');
views.forEach(function (view)
{
_this.continue = true;
var guid = view.search({ "type": "resource" })[0].data.guid;
jQuery.ajax({
url: "api/forge/modelderivative/metadata/model",
data: {
"urn": urn,
"viewableId": guid,
},
success: function (metadata) {
_this.getIds(metadata.data);
if (_this.listdbId.includes(dbId[0])) {
var newOpt = new Option(view.data.viewableID, view.data.name);
selectBox.append(newOpt);
}
_this.listdbId = []
}
});
});
selectBox = selectBox[0];
selectBox.change(function (opt) {
//launch change function
});