I am trying to get $.when
to work with my code. the case is that i have a method that fires alot of Ajax requests, and i want to show a loading screeen for the user while the requests rune. The when is so i can hide it after. Given what i have learned about $.when
should the following code work, but the when function is never fired.
self.createTaggingDialog(self);
var ajaxArray = new Array();
self.containers.each(function () {
var ImageClass = $(this).ImageTags();
if (ImageClass != null) {
ajaxArray.push(ImageClass.TagUser(ImageClass, username));
}
});
$.when(ajaxArray, function () {
console.log("DONE!");
self.RemoveTagggingDialog(self);
});
Here is a value of the ajaxArray
when it reaches the $.when
The TagUser:
TagUser(self: ImageTags, username: string) {
return $.ajax({
type: "POST",
url: self.options.UrlTagUser,
data: {
username: username,
imageid: self.options.ImageId
},
success: function (data: UserAddJson) {
if (data.Successful) {
if (self.AddUserElement != null) {
self.AddUserElement.find('input').val('');
self.AddUserElement.modal('hide');
}
self.TagUserSuccess(self, data);
} else {
self.TagUserError(self, data.Message);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
self.TagUserError(self, "");
}
});
}