Home Display some simple data in HTML
Reply: 0

Display some simple data in HTML

user8395
1#
user8395 Published in September 19, 2018, 9:09 am

activeUsers.getUsers() returns a list with the online users in my app.

I want to display it in my HTML but I have no idea how to do this. I'm getting error 404 on my ajax request yet if I put a breakpoint in my controller it shows the list of online users.

Any help??

Controller

  @RequestMapping(value = "/loggedUsers", method = RequestMethod.GET)
public String getLoggedUsers(Model model) {
    model.addAttribute("loggedUsers", activeUsers.getUsers());
    return "loggedUsers";
}

AJAX

$(document).ready(function () {

//get loggedUsers
$.ajax({
    url: '/loggedUsers',
    type: 'get',
    success: function (loggedUsers) {
        console.log(loggedUsers);
    }
});
});

HTML

<div id="sidebar-right" class="visible">
<ul class="sidebar-nav">
    <li id="dashboard">
        <a href="dashboard">
            <c:forEach var="loggedUser" items="${loggedUsers}">
                <span class="menu-title">${loggedUser}</span>
            </c:forEach>
        </a>
    </li>
</ul>

the console log returns:

error 404

share|improve this question
  • the ajax returns 404 but it's calling the function – user9658240 Apr 17 at 11:08
  • 1
    You aren't returning the list of users but a view. The loggedUsers.jsp (or whatever view technology you use cannot be found). Instead just return the list of users and annotate the method with @responseBody that way you get the list of users as JSON and then user some JS to render the list. – M. Deinum Apr 17 at 11:11
  • you are right. thx – user9658240 Apr 17 at 11:14

1 Answer 1

active oldest votes
up vote 0 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.293849 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO