I’m having some problems with this jQuery….I’m new to it. It looks like it’s the same as the example I’m taking it from…
$.getJSON('<%= Page.ResolveUrl("~/MyService.aspx") %>',
function(data) {
$.each(data, function(index, elem) {
alert(elem.Name);
});
}
);
elem.Name always says ‘undefined’! I’m getting the following data returned from my service…
{"ID":1,"Name":"David Bowie"}
You’re getting mixed up in how
.eachworks.This by itself would work:
datain your JSON callback is your JSON data.The
.eachfunction will iterate through all the elements in that object and call your function once for each element. So your function would get called twice — once withindexbeingIDand once withindexbeingName. That doesn’t seem at all appropriate given the object you have.