现在应该很少有人使用jQuery了吧!为了回顾以前使用jQuery的经历,现在特意做了一个使用Ajax渲染数据的小例子。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>用户列表</title> </head> <body> <div id="app"> <h3>用户列表</h3> <table> <thead> <tr> <th>ID</th> <th>用户名</th> </tr> </thead> <tbody> </tbody> </table> </div> </body> <script src="jquery/dist/jquery.js"></script> <script> jQuery.ajax({ url: 'http://localhost:8080/user/list', success: function (response) { response.forEach(function (item) { $('#app table tbody').append('<tr>').children().last() .append('<td>').children().append(item.id) .after('<td>').next().append(item.username); }); } }) </script> </html>
复制