1

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

0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

-1

Have you tried using jQuery getJSON method:

http://docs.jquery.com/Ajax/jQuery.getJSON

1 Comment

That will perform a GET operation instead of a POST.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.