title: How do I wait for an action to finish before showing the next alert using sweetalert2
body: <p>So I have an ASP.NET MVC Core project and when I click a button I want to display an alert using  sweetalert2.</p>
  <p>The button looks like this</p>
  <pre><code>&lt;a class=&quot;btn btn-primary&quot; onclick=&quot;doFunction(@(JsonConvert.SerializeObject(number))); &quot;&gt;Click&lt;/a&gt;
  </code></pre>
  <p>And the JavaScript looks like this</p>
  <pre><code>function doFunction(model) {
          Swal.queue([{
              title: 'TestData',
              confirmButtonText: 'OK',
              text: 'TestData',
              showLoaderOnConfirm: true,
              preConfirm: () =&gt; {
                  $.ajax({
                          type: &quot;POST&quot;,
                          url: '@Url.Action(&quot;Tester&quot;, &quot;Home&quot;)',
                          contentType: &quot;application/json; charset=utf-8&quot;,
                          data: { data: &quot;yourdata&quot; },
                          dataType: &quot;json&quot;,
                          //success: function(recData) { alert('Success'); },
                          //error: function() { alert('A error'); }
                  }).then(Swal.insertQueueStep(&quot;Woo&quot;, &quot;Woo&quot;))
                      .catch(() =&gt; {
                          Swal.insertQueueStep({
                              icon: 'error',
                              title: 'Something went wrong'
                          })
                      });
              }
          }])
      }
  </code></pre>
  <p>And here is the Action</p>
  <pre><code>public IActionResult Tester()
          {
  
              using (var context = new DbContext(_context))
              {
                  var user = context.Users.FirstOrDefault(x =&gt; x.UserName == &quot;TheUser&quot;);
                  return new JsonResult(user.UserName);
              }
          }
  </code></pre>
  <p>And right now it displays an alert, and when I click &quot;OK&quot; it shows the next alert but no loading window inbetween.</p>
  <p>How do I properly call an action that's inside a controller and display a loading alert while it waits for the action to finish, followed by a finished alert.</p>