1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <script src="./lib/jquery.js"></script> <script> renderBook(); $('#btnAdd').on('click', function() { var val1 = $('#iptBookname').val().trim(); var val2 = $('#iptAuthor').val().trim(); var val3 = $('#iptPublisher').val().trim();
if (val1 === '' || val2 === '' || val3 === '') { alert('请输入完整的数据'); return; }
var kids = '添加书的接口addbooks'; $.post(kids, { bookname: val1, author: val2, publisher: val3 }, function(res) { if (res.status === 201) { renderBook(); $('#bookname').val(); $('#author').val(); $('#publisher').val(); } }) });
function renderBook() { var kid = '获取书的接口getbooks'; $.get(kid, function(res) {
if (res.status !== 200) { return; }; var data = res.data; console.log(data) var str = ''; $.each(data, function(k, r) { str += ' <tr>\ <td>' + r.id + '</td>\ <td>' + r.bookname + '</td>\ <td>' + r.author + '</td>\ <td>' + r.publisher + '</td>\ <td><a href="javascript:;">删除 </a><td>\ </tr>; ' }); $('#tb').html(str); }); } </script>
|