hy i am creat a form and i am submit the form using ajax and i recive the list of data in my success ajax
this is my form :
<form id="myForm" method="POST">
<input type="submit" value="Refresh">
</form>
this is my view function
def refresh(request):
user = usertab.objects.all().values()
d={"data" : list(user)}
return JsonResponse(d)
and this is my 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']){
alert(a)
}
},
error: function(xhr, status, error) {
alert(xhr.responseText);
}
});
});
ia ma recive all user data in my success ajax and i want to print this data in table using for loop how i do that please tell me
i am apply for loop in dict but i am got alert in aray form 0 then 1 then 2 i want to print this data in hrml table please tell me
this is my 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>