Reputation:
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.
Upvotes: 0
Views: 188
Reputation:
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.
Upvotes: 1