Ajax.BeginForm,呼吁行动,返回JSON,如何访问JSON对象在我的onSuccess JS功能? [英] Ajax.BeginForm, Calls Action, Returns JSON, How do I access JSON object in my OnSuccess JS Function?
问题描述
Ajax.BeginForm
调用一个动作,然后返回JSON。
如何访问JSON对象在我的的onComplete
js函数?
所以我的 Ajax.BeginForm
看起来像这样...
使用(Ajax.BeginForm(优惠券,新AjaxOptions {=的onSuccessCouponSubmitted}))
和我的的onSuccess
函数看起来像这样...
函数CouponSubmitted(){
VAR数据= response.get_response()的get_object()。
警报(data.success);
}
我也试过...
函数CouponSubmitted(数据){
警报(data.success);
}
我的控制器优惠券返回此...
返回JSON(新{成功=假,nameError = nameError,emailError = emailError});
被返回关于如何访问JSON的任何想法?
函数的onSuccess(五){//功能CouponSubmitted(数据)的问题
VAR JSON = e.get_response()的get_object()。
警报(json.success);
}
这是什么AJAX.BeginForm的onSuccess回调期望你做的就是你的JSON回来。
希望我救了别人在这一段时间,下得离谱记录功能?
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?
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?".
这篇关于Ajax.BeginForm,呼吁行动,返回JSON,如何访问JSON对象在我的onSuccess JS功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!