Here is my html and ajax
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title></title>
- <script src="Scripts/jquery-3.3.1.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function (){
- var UserLists = $('#Userlist');
- $('#btnUsers').click(function () {
- $.ajax({
- type: 'GET',
- url: 'api/employees/',
- dataType: 'json',
- success: function (data) {
- UserLists.empty();
- $.each(data, function (index, val) {
- var Username = val.Username;
- UserLists.append('<li>' + Username+'</li>')
- });
- }
- });
- });
- $('#btnClear').click(function () {
- UserLists.empty();
- });
- });
- </script>
- </head>
- <body>
- <input type="button" id="btnUsers" value="GetUsersList"/>
- <input type="button" id="btnClear" value="Clear Users"/>
- <ul id="Userlist"/>
- </body>
- </html>
My controller code is here
- public class EmployeesController : ApiController
- {
- [HttpGet]
- public IEnumerable<User> Get()
- {
- using (LoginEntities ln = new LoginEntities())
- {
- return ln.Users.ToList();
- }
- }
- [HttpGet]
- public HttpResponseMessage Get(int id)
- {
- using (LoginEntities dd = new LoginEntities())
- {
- var entity = dd.Users.FirstOrDefault(e => e.UserId == id);
- if (entity != null)
- {
- return Request.CreateResponse(HttpStatusCode.OK, entity);
- }
- else
- {
- return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee Id " + id.ToString() + "Not found");
- }
- }
- }
when i inspect the data is there but the UL is not binding and not showing the data on page there is no error on console Jquery is working fine i check it with alert.