Note that there are some explanatory texts on larger screens.

plurals
  1. POAsp.NET MVC AjaxOptions OnSuccess fires.. too early?
    primarykey
    data
    text
    <p>I'd like to use the OnSuccess option of AjaxOptions passed as Ajax.BeginForm argument to "do something" once the response is completely received and DOM updated. As far as I can undestand from MSDN, this is what this option do.</p> <p>In my application, OnSuccess script fires too early, immediately after the request is sent. I put to sleep the thread for a while, to better see the result. I supposed to see the OnSuccess script (an alert) fired after that sleep time, say, 2 seconds. I use Firebug to see what's happening under the hood, and all I see is: I click the button (submit inside the ajax form), alert is shown (2 seconds before expected), after 2 seconds firebug shows the request-response and nothing more happens.</p> <p>Where I'm wrong?</p> <p>Thanks in advance, mt</p> <p>Some sample code, as correctly asked (I started a blank new solution using Asp.NET MVC template in VS):</p> <p><b>Home/Index view:</b></p> <pre><code>&lt;asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;div id="divPlaceholder"&gt; &lt;% using (Ajax.BeginForm("DoLongTask", "Home", new AjaxOptions() { UpdateTargetId = "divPlaceholder", InsertionMode = InsertionMode.Replace, OnSuccess = "alert('onsuccess fired')" })) { %&gt; &lt;input type="submit" value="button" /&gt; &lt;% } %&gt; &lt;/div&gt; &lt;/asp:Content&gt; </code></pre> <p><b>HomeController</b></p> <pre><code>public ActionResult DoLongTask() { if (Request.IsAjaxRequest()) { System.Threading.Thread.Sleep(2000); return View(); } else { throw new NotSupportedException(); } } </code></pre> <p>I think this is enough to reproduce the behavior. An empty partial view can be used as DoLongTask view.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload