Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <code>OnFailure</code> and <code>OnSuccess</code> instead of <code>OnComplete</code>; <code>OnSuccess</code> gives you the data as a proper JSON object. You can find the callback method signatures burried in <code>~/Scripts/jquery.unobtrusive-ajax.min.js</code> which you should load on your page.</p> <p>In your <code>Ajax.BeginForm</code>:</p> <pre><code>new AjaxOptions { OnFailure = "onTestFailure", OnSuccess = "onTestSuccess" } </code></pre> <p>Script block:</p> <pre><code>&lt;script&gt; //&lt;![CDATA[ function onTestFailure(xhr, status, error) { console.log("Ajax form submission", "onTestFailure"); console.log("xhr", xhr); console.log("status", status); console.log("error", error); // TODO: make me pretty alert(error); } function onTestSuccess(data, status, xhr) { console.log("Ajax form submission", "onTestSuccess"); console.log("data", data); console.log("status", status); console.log("xhr", xhr); // Here's where you use the JSON object //doSomethingUseful(data); } //]]&gt; &lt;/script&gt; </code></pre> <p>These signatures match <a href="http://api.jquery.com/jQuery.ajax/"><code>success</code> and <code>error</code> callbacks in $.ajax(...)</a>, which might not be such a surprise after all.</p> <p>This was tested using <a href="/questions/tagged/asp.net-mvc-3" class="post-tag" title="show questions tagged 'asp.net-mvc-3'" rel="tag">asp.net-mvc-3</a> with <a href="/questions/tagged/jquery" class="post-tag" title="show questions tagged 'jquery'" rel="tag">jquery</a> 1.6.3 and 1.7.2.</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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