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

asked Jan 11, 2010 at 15:01
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.

answered Jan 11, 2010 at 15:10
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

answered Jan 11, 2010 at 15:08

1 Comment

That will perform a GET operation instead of a POST.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.