javascript - Getting the result one by one from Ajax Request -
i have next files
index.html<div><ul></ul></div> <button>click me</button>
main.js $.ajax({ type: 'post', url: 'get_db.php', data: {name: 'users'}, success: function(result) { $(result).hide().appendto('div ul').fadein(1000); } });
get_db.php include('db_connect.php'); $db_name = $_post['name']; $query = "select * ".$db_name; if($result = $conn->query($query)) { while($row = $result->fetch_assoc()) { $content .= "<li>".$row['id']." ".$row['name']."</li>"; echo $content; } }
and question is: how can results 1 1 , append 'div ul'? in case result show @ once.
you can iterate on <li>
elements in response, , append each @ time timeout
$.ajax({ type : 'post', url : 'get_db.php', info : {name: 'users'} }).done(function(result) { $(result).each(function(index, li) { settimeout(function() { $(li).hide().appendto('div ul').fadein(1000); }, index * 300); }); });
javascript jquery ajax
No comments:
Post a Comment