1、html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <script type="text/javascript" src="myresource/bootstrap/js/jquery-3.1.1.min.js"></script> <script type="text/javascript" src="list.js"></script> </head> <body> <table > <table id="td"> <tr> <Td> ID </ td> <Td> Name </ td> <Td> Password </ td> </tr> </table> </table> </body> </html>
2, js (that is, the contents of the document ready function)
1 $.post( 2 "http://localhost:8080/list", 3 function(obj){ 4 5 for(var i in obj){ 6 $("#td").append("<tr><td>"+obj[i].sid+"</td><td>"+obj[i].sname+"</td><td>"+obj[i].pwd+"</td></tr>"); 7 } 8 9 },"json" 10 ); 11
3, browser access localhost: 8080 / static resources