Hiten Pandya

Hiten Pandya

  • 759
  • 1.7k
  • 13.2k

Not able to get the Integer value from ajax success function

Dec 22 2017 12:47 PM
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
 
 
  1. $(document).ready(function () {  
  2.         var r = new Array();  
  3.         var j = -1;  
  4.         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>'  
  5.         $.ajax({  
  6.             type: "GET",  
  7.             url: "/api/EmployeeAPI/",  
  8.             success: function (result) {  
  9.                 //alert(result[0]["FirstName"]);  
  10.                 for (var i in result) {  
  11.                     var data = result[i];  
  12.                     alert(result[0]["HREmpID"]);  
  13.                     r[++j] = '<tr>';  
  14.                     r[++j] = '<td>';  
  15.                     r[++j] = data.HREmpID;  
  16.                     r[++j] = '</td>';  
  17.                     r[++j] = '<td>';  
  18.                     r[++j] = data.FirstName + " " + data.LastName;  
  19.                     r[++j] = '</td>';  
  20.                     r[++j] = '<td>';  
  21.                     r[++j] = data.Address;  
  22.                     r[++j] = '</td>';  
  23.                     r[++j] = '<td>';  
  24.                     r[++j] = data.City;  
  25.                     r[++j] = '</td>';  
  26.                     r[++j] = '</tr>';  
  27.                 }  
  28.                 r[++j] = '</tbody></table>';  
  29.                 $("#empDetails").html(r.join(''));  
  30.             }  
  31.         });  
  32.     });  
but I always getting the undefined for HRempID. I don't know what is going wrong ? any help will be appreciate. Thanks in advance.

Answers (4)