0

From my jQuery file, I call a function from my controller which returns a Json object, as below:

[AcceptVerbs(HttpVerbs.Get)]
        public ActionResult MatrixTypes()
        {

            var matrix = Enum.PricingMatrixType();

            return Json(matrix);

        }

The call is made by the following function, I'm posting only an excerpt that really matters:

 var matrix;

                                            $.get(
                                            MatrixTypeUrl, 
                                            function(data) {
                                                matrix = JSON.parse(data);
                                                for (var i = 0; i < matrix.length; i++) {
                                                    html += String.format('<option value="{0}">{1}</option>', matrix[i].Value, matrix[i].Text);
                                                }

When I press a button on my page, this function gets correctly called, but blows up at the line "matrix = JSON.parse(data);"

The data object has data, I double checked it on the call by debugging.

This was the error I got:

JSON.parse [Break on this error] matrix = JSON.parse(data);

What do you think I can do about this?

EDIT: By using Firebug, I could also confirm that the JSON object is not empty, this is the response of the server:

[{"Text":"Valor Único","Value":"0"},{"Text":"Intervalo","Value":"1"},{"Text":"Valor Adicional","Value":"2"}]
3
  • The content-type is application/json; charset=utf-8 Commented Aug 6, 2010 at 10:41
  • 1
    A tipp: as you use jquery you could use the getJSON function instead of get. This way the result is automatically parsed and validated. Commented Aug 6, 2010 at 11:10
  • Really? Thanks for the tip, I'll start using it that way then. I'll read more on it later :) Commented Aug 6, 2010 at 11:12

1 Answer 1

1

Nevermind this problem, I fixed it. It was missing some calls at the initializer of the jQuery class and so it had errors way before it arrived at the call of JSON.parse(data).

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

Comments

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.