<div>
<table class="table table-hover table-bordered table-striped">
<thead>
<tr>
<th>注册码</th>
<th>注册时间</th>
<th>有效时间(天)</th>
<th>关联应用</th>
</tr>
</thead>
<tbody id="tb">
</tbody>
</table>
</div>
<script>
$('#iscode').click(function () {
$.ajax({
url: '/v1/regcode/list2/',
type: 'post',
data: {
'validperiod': $('#validperiod').val(),
'count': $('#count').val(),
'application': $('#application').val(),
'csrfmiddlewaretoken': '{{ csrf_token }}'
},
success: function (data) {
if (data.code == 100) {
window.alert(data.msg);
var obj = data.res;
for (var i = 0; i < obj.length; i++){
// 创建标签
tr = $('<tr></tr>');
// 为标签添加ID
tr.attr('id', 'id_' + i);
// 给tr标签中添加td标签并添加内容
tr.append($('<td></td>').text(obj[i].regcode));
tr.append($('<td></td>').text(obj[i].createdate));
tr.append($('<td></td>').text(obj[i].validperiod));
tr.append($('<td></td>').text(obj[i].application));
// 获取tbody标签,将tr标签添加进去
$('#tb').append(tr);
console.log(tr);
}
} else {
if (data.code == 104){
$('.verror').text(data.msg)
}
}
}
})
});
</script>