javascript - JQuery $.when with ajax array -
this question has answer here:
- pass in array of deferreds $.when() 9 answers
i trying $.when work code. case have method fires alot of ajax requests, , want show loading screeen user while requests rune. when can hide after. given have learned $.when should following code work, when function 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 value of ajaxarray when reaches $.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, ""); } }); }
try
$.when.apply($, ajaxarray).done(function () { console.log("done!"); self.removetagggingdialog(self); });
Comments
Post a Comment