Issue with JSON and jQuery

Posted by Jason N. Gaylord on Stack Overflow See other posts from Stack Overflow or by Jason N. Gaylord
Published on 2010-04-13T19:46:28Z Indexed on 2010/04/13 19:53 UTC
Read the original article Hit count: 369

I'm calling a web service and returning the following data in JSON format:

["OrderNumber":"12345","CustomerId":"555"]

In my web service success method, I'm trying to parse both:

$.ajax({
    type: "POST",
    url: "MyService.asmx/ServiceName",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg) {
        var data = msg.d;
        var rtn = "";

        $.each(data, function(list) {
            rtn = rtn + this.OrderNumber + ", " + this.CustomerId + "<br/>";
        }

        rtn = rtn + "<br/>" + data;

        $("#test").html(rtn);
        }
    });

but I'm getting a bunch of "undefined, undefined" rows followed by the correct JSON string. Any idea why? I've tried using the eval() method but that didn't help as I got some error message talking about ']' being expected.

© Stack Overflow or respective owner

Related posts about JSON

Related posts about jQuery