Reputation: 5341
Im calling my ajax on the following
function LoadAudit(value) {
$.ajax({
url: '/Account/GetAuditRecord/' + value,
success: function (data) {
$("#htmlResult").val(data.html);
},
error:function(data) {
alert('error');
},
});
};
Which calls my controller
public JsonResult GetAuditRecord(string Id)
{
string html =_auditLogService.FindAllByAccount().Single(a => a.Id == Id).Comments ;
return Json(new { html = result});
}
Which works (data is looked up and ready to pass back), but error is being fired in jquery, when success should be, what have I missed?
Upvotes: 0
Views: 87
Reputation: 18873
Add dataType
as 'JSON'
in ajax call as shown:
$.ajax({
url: '/Account/GetAuditRecord/' + value,
dataType : 'JSON',
success: function (data) {
$("#htmlResult").val(data.html);
},
error:function(data) {
alert('error');
},
});
and change jsonresult in controller action as shown:
return Json(new { html = result }, JsonRequestBehavior.AllowGet);
Upvotes: 3
Reputation: 101
Change your Controller
return type:
return Json( new { html = result }, JsonRequestBehavior.AllowGet );
Upvotes: 0