My code runs as,
$.ajax({
url: "api/WepAPI/",
dataType: 'json',
success: function (result) {
alert(result.length);
$.each(result, function (index, element) {
alert(element.StartDate);
});
},
});
while iterating it shows the first element’s startdate correctly and for all other elements it returns the
undefined message in the alert.
My WEBAPI contoller code looks like,
public IEnumerable<Employees> GetAllEmployess()
{
EmpDataContainer context = new EmpDataContainer();
return context.Employees.AsEnumerable();
}
Help me in sorting out this error…
It appears your data might not be what you are expecting or maybe it is missing something or perhaps it is lower/different letter case.
In either case, without begin able to see the JSON for result; it is not possible to identify the possible cause for this issue.
Can you please add the JSON for a typical result object?
You can use
console.log(result);to output the JSON.