javascript - JQuery $.when with ajax array -


this question has answer here:

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 enter image description here

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

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -