Ajax.BeginForm, Calls Action, Returns JSON, How do I access JSON object in my OnSuccess JS Function?

asp.net-mvc, jquery, json

Solution

function OnSuccess(e) { //function CouponSubmitted(data) in the question
   var json = e.get_response().get_object();
   alert(json.success);
}

This is what the AJAX.BeginForm OnSuccess callback expects you to do to get your JSON back.

Hope I saved someone else some time on this ridiculously under documented "feature?".

Problem

`Ajax.BeginForm` calls an action and then returns JSON. How do I access JSON object in my `OnComplete` js function? so my `Ajax.BeginForm` looks like this... ``` using (Ajax.BeginForm("Coupon", new AjaxOptions { OnSuccess = "CouponSubmitted" })) ``` and my `OnSuccess` function looks like this... ``` function CouponSubmitted() { var data = response.get_response().get_object(); alert(data.success); } ``` I also tried... ``` function CouponSubmitted(data) { alert(data.success); } ``` My controller "Coupon" returns this... ``` return Json(new { success = false, nameError = nameError, emailError = emailError }); ``` Any ideas on how to access the Json that gets returned?

Original source

Related problems