0
function success(arg) {
var obj = arg.get_response().get_object();
if (obj.ErrorMessage === '') {
var answer = document.createElement('div');
answer.appendChild(document.createTextNode(obj.Answer));
document.getElementById('answers').appendChild(answer);
} else {
document.getElementById('errors').innerHTML = obj.ErrorMessage;
}
}
<% using (Ajax.BeginForm("EditOrganizationMeta", "Organization", new AjaxOptions { HttpMethod = "POST", OnSuccess = "success" })) { %>
<input type="submit" name="button<%=OrganizationMeta.vcr_MetaKey + Lang.int_LangId %>" value="Save" />
<div id="errors"></div>
<div id="answers"></div>
<% } %>
控制器:
[HttpPost]
[ValidateInput(false)]
public ActionResult EditOrganizationMeta(FormCollection collection)
{
return Json(new { Answer = "Record Successfully Saved", ErrorMessages = "Title is required" });
}
的事情是,在JavaScript中的成功方法沒有得到所需要的參數。它在那裏打印undefined。 javascript方法OnSuccess中有問題嗎?