【发布时间】:2020-10-07 05:07:39
【问题描述】:
我正在尝试在不刷新页面的情况下阻止/取消阻止用户。如果status=1,会显示Block选项,如果status=0,会显示Unblock选项
调用该函数后,views.py中的状态会变为0或1 该功能工作正常,但刷新页面后显示
如何在不刷新页面的情况下显示该值
<table id='usersTable' class="table table-bordered">
<thead>
<tr>
<th>S.No.</th>
<th>Name</th>
<th>Email</th>
<th>Block/Unblock</th>
</tr>
</thead>
<tbody>
{% for userid, name, email, status in comb_lis %}
<tr id='usr-{{name}}'>
<input type="hidden" id="{{userid}}" name="{{userid}}" value="{{userid}}">
<input type="hidden" id="{{name}}" name="{{name}}" value="{{name}}">
<td>{{forloop.counter}}</td>
<td>{{name}}</td>
<td>{{email}}</td>
<td> <a href="#" onclick="restrictUser(document.getElementById('{{userid}}').value, document.getElementById('{{name}}').value)">
{% if status == "1" %}
Block
{% else %}
Unblock
{% endif %}
</a></td>
</tr>
{% endfor %}
</tbody>
这是ajax函数
function restrictUser(userid, name) {
$.ajax({
url: '/restrict-user-ajax/'+userid,
dataType: 'json',
success: function (data) {
if (data.status) {
alert("User Blocked!");
}
}
});
}
感谢任何帮助
【问题讨论】:
标签: python html jquery django ajax