Hi I am submitting a html form using ajax and I am receiving a JSON Array response in return. So can you please suggest me how can I append this response in html table dynamically.
this is my form :
<form id="myForm" method="POST">
<input type="submit" value="Refresh">
</form>
Python Django Backed Code:
def refresh(request):
user = usertab.objects.all().values()
d={"data" : list(user)}
return JsonResponse(d)
And here I am calling my BE code using Ajax :
$(document).on('submit','#myForm',function(e){
e.preventDefault();
$.ajax({
type:'POST',
url: '/refresh/',
data:{
csrfmiddlewaretoken : "{{ csrf_token }}"
},
success: function(d){
for (a in d['data']){
//How to append data in html table
}
},
error: function(xhr, status, error) {
alert(xhr.responseText);
}
});
});
This is my html table :
<table id="myTable">
<thead>
<tr>
<th>id</th>
<th>username</th>
<th>email</th>
</tr>
</thead>
<tbody>
<tr>
<td> ??????? </td>
<td> ??????? </td>
</tr>
</tbody>
</table>