TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mark Tabor
585
2k
460.2k
My AJAX is not binding the UL list item below is the code
Mar 21 2019 12:26 PM
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.
Reply
Answers (
12
)
public partial class form: System.Web.UI.Page
What does this line mean and what does it do