I have the following getJSON that calls an MVC controller which returns inforamtion back:
$.getJSON('@Url.Action("List", "Spkr")',
{ id: spkrid},
function (data) {
$.each(data.spk, function () {
alert(spk.ID);
});
});
The JSON object looks like the following: {"spk":[{"ID":31,"Title":"SprkTitle","Status":"Onlne"}]}
The .each is not showing the anything in the alert. Not sure if I have it configured wrong.
I see no definition/declaration of spk
the $.each method can take a function like function(index, value)
as the second parameter where index is the index of the current item and value is its value i.e. data.spk[index == value
So this should work
$.each(data.spk, function (index, spk) {
alert(spk.ID);
});