Hello all, I am new to Web API and try to get the HREmpID from my ajax response but unfortunetly I am getting undefined.Below screen shot will provide more information in case if you need.
And in the below code is of ajax code that will get the records from the api
- $(document).ready(function () {
- var r = new Array();
- var j = -1;
- r[++j] = '<table border = 1><thead><tr><th>HREmpID</th><th>Name</th><th>Address</th><th>City</th><th>Action</th></tr></thead><tbody>'
- $.ajax({
- type: "GET",
- url: "/api/EmployeeAPI/",
- success: function (result) {
-
- for (var i in result) {
- var data = result[i];
- alert(result[0]["HREmpID"]);
- r[++j] = '<tr>';
- r[++j] = '<td>';
- r[++j] = data.HREmpID;
- r[++j] = '</td>';
- r[++j] = '<td>';
- r[++j] = data.FirstName + " " + data.LastName;
- r[++j] = '</td>';
- r[++j] = '<td>';
- r[++j] = data.Address;
- r[++j] = '</td>';
- r[++j] = '<td>';
- r[++j] = data.City;
- r[++j] = '</td>';
- r[++j] = '</tr>';
- }
- r[++j] = '</tbody></table>';
- $("#empDetails").html(r.join(''));
- }
- });
- });
but I always getting the undefined for HRempID. I don't know what is going wrong ? any help will be appreciate. Thanks in advance.