javascript - Mootools list filter with periodical request to the server -
i have html markup (online users list):
<div id="users"> <div class="users_row" title="user1">user1</div> <div class="users_row" title="user2">user2</div> <div class="users_row" title="user3">user3</div> <div class="users_row" title="user4">user4</div> </div>
my mootools js function below (periodical function every 5 seconds):
get_users: function() { new request.json({ initialdelay: 1, delay: 10000, limit: 25000, method: 'post', url: 'handler.php', onsuccess: function(data){ if (data.users.length) { data.users.each(function(u){ /*wrong...*/ new element('div', {'html':u.name, 'class': 'user_row', 'title': u.name}).inject(document.id('users')); }); } } }); }
for example user1, user2, user3, user5 handler.php. how can rebuild online users list?
<div id="users"> <div class="users_row" title="user1">user1</div> <div class="users_row" title="user2">user2</div> <div class="users_row" title="user3">user3</div> <!--<div class="users_row" title="user4">user4</div>!--> // remove user4 <div class="users_row" title="user5">user5</div> // add user5 </div>
p.s: answer not acceptable :)
document.id('users').set('html', '<div class="users_row" title="'+u.name+'">'+u.name+'</div>);
thanks.
p.s: json sample server:
{"users":[{"name":"user1"},{"name":"user2"},{"name":"user3"},{"name":"user5"}],"total":4}
try this:
check demo here
for (i = 0; < users.users.length; i++) { var el = new element('div', { 'class': 'users_row', 'html': users.users[i].name }); el.inject(usersdivid); }
Comments
Post a Comment