jQuery $.when() with variable arguments

后端 未结 1 828
南笙
南笙 2020-12-06 00:37

I want to send [1, n) AJAX-requests to the server and after all have returned a result a modal dialog should be closed. $.when(a(), b(), c()) would be perfect,

相关标签:
1条回答
  • 2020-12-06 00:56

    Call the functions and add their return values to an array. Then call $.when passing the array as argument like so:

    $.when.apply($, array)
    

    See Function.prototype.apply [MDN] for more information and my answer here for an extended example.

    0 讨论(0)
提交回复
热议问题