0

I want to use $.when() to execute code after several Ajax.BeginForm forms on the page have completed submission. Each of the forms can be submitted like so:

$('#formA').submit();
$('#formB').submit();

After reading this answer, I attempted the following:

$.when($('#formA').submit(), $('#formB').submit()).done(function(a1, a2)
{
   alert('Finished!');
}

Unfortunately this does not work - all forms return immediately and the "Finished!" dialogue box appears right away even though the ajax requests are still processing. I know they're not finished processing b/c at this point none have made a callback to their AjaxOptions' onComplete function. The example linked above uses an

return $.ajax({ });

block to designate the promise that the $.when() should wait for. Presumably this is why my code does not work - as far as I know, I am not able to mandate a return on the Ajax.BeginForm element.

Does anyone have a suggestion for how I can use $.when() in conjunction with multiple Ajax.BeginForm asynchronous requests?

Thanks in advance!

Community
  • 1
  • 1
OneManBand
  • 528
  • 5
  • 24
  • 1
    `.submit()` is not an ajax request. Replace those with `.ajax(options)`. And forget about using the AjaxHelper. – Jasen Jan 25 '16 at 23:26
  • So is that to say that .when cannot be used with Ajax.BeginForm? Could you expand just a little on your comment? Thank you :D – OneManBand Jan 26 '16 at 02:06
  • 1
    In this case I don't see extension points for AjaxHelper to get promises to work. I avoid the AjaxHelper as it does little for me. Often I find I must do some customization to my AJAX calls which requires me to figure out how the helper works _OR_ I can spend that time to figure out how to make it work going the more platform-agnostic jQuery way. In other words 1) AjaxHelper knowledge does not easily transfer to non-MS tech. 2) There are many more AJAX examples to be found that does not use AjaxHelper. – Jasen Jan 26 '16 at 02:28
  • Very helpful, thanks! I will convert the helpers to a more generic form so I can use the complete ajax toolkit. – OneManBand Jan 26 '16 at 04:05

0 Answers0