I currently have a controller method that returns a JsonResult:
public JsonResult EditField(int FieldID, string FieldValue)
{
var f = ManagerProvider.GetFieldManager();
try
{
f.UpdateField(FieldID, FieldValue);
return Json(new { State = "Success", Message = "Success"});
}
catch (Exception ex)
{
return Json(new { State = "Error", Message = ex.Message });
}
}
When I post this using jQuery ($.post), the callback function is initiated, where I consume the returned Json object. I can print out the feedback, which appears as
{"State" : "Error", "Message" : "Invalid input"}
However, when I go to get individual parts of this in the Javascript, by using
alert(data.State);
All I get from this is "undefined".
Has anybody got any ideas please?
Cheers,
Chris
2 Answers 2
Are you positive that you specify "json" as return data type ?
$.postJSON = function(url, data, callback) {
$.post(url, data, callback, "json");
};
Taken from the jQuery.post documentation page.
Comments
Have you tried using jQuery getJSON method: