0

I'm really new at this. And I'm really stuck. I have the jquery code, it will load data from Web API, but it does not display on my page.

$.getJSON("/api/Order", function(data) {
            if (data != null) {
                var str = '';
                $.each(data, function (item) {
                    str = '<li>' + item.ItemName + '</li>';
                });
                $("#contents").append(str);
            }
        });

Can anyone explain what is going on? Thanks.

1 Answer 1

1

try this:

$.getJSON("/api/Order", function(data) {
            if (data != null) {
                var str = '';
                $.each(data, function (key,item) {
                    str = '<li>' + item.ItemName + '</li>';
                });
                $("#contents").append(str);
            }
        });

I added "key" in $.each(data, function (key,item), because data returned from Web API is JSON type.

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.