我正在使用switchery.js以交互方式将状态设置为激活/停用。
此按钮的作用是,每当有人要取消激活用户/帖子时,该按钮将切换并在数据库中更新,反之则由Versa激活。
但是,假设我单击了按钮,但是由于未在数据库中对其进行更新而发生了一些错误,因此我想将按钮恢复到其初始状态。
下面是我用来显示按钮的PHP代码
if($row['status'] == 1)
{ $checked = "checked"; }
elseif($row['status'] == 0)
{ $checked = ""; }
<input type='checkbox' class='switchery' data-id='".$row['id']."' data-size='xs' {$checked}/>
下面是我用来与按钮交互的jQuery代码
$("body").on("click", ".switchery",function()
{
var id = $(this).parent().find(".switchery").data("id");
var check = $(this).parent().find("input").is(':checked');
$.ajax({
url: '/bypasser/modules/view',
type: 'POST',
dataType: 'JSON',
data: {action: "change", type: "user", id: id, status: check},
})
.done(function(resp)
{
if(resp.status == "status blank")
{
toastr.error("Error Processing Request! Refresh and Try Again.","Error!",{progressBar:!0,showMethod:"slideDown",hideMethod:"slideUp",timeOut:2e3,preventDuplicates: true,positionClass: "toast-bottom-right"});
}
if(resp.status == "super_admin")
{
toastr.info("Cannot Deactivate Superadmin!","Info!",{progressBar:!0,showMethod:"slideDown",hideMethod:"slideUp",timeOut:2e3,positionClass: "toast-bottom-right"});
}
if(resp.status == "success")
{
if(check == "true" || check == true)
check = "Activated";
else if(check == "false" || check == false)
check = "Deactivated";
toastr.success("User <b>"+check+"</b> Successfully!","Success!",{progressBar:!0,showMethod:"slideDown",hideMethod:"slideUp",timeOut:2e3,positionClass: "toast-bottom-right"});
}
if(resp.status == "error")
{
toastr.error("Error Changing Status! Try after Sometime.","Error!",{progressBar:!0,showMethod:"slideDown",hideMethod:"slideUp",timeOut:2e3,preventDuplicates: true,positionClass: "toast-bottom-right"});
}
else
{
console.log(resp);
}
});
});
下面是我从控制台窗口从chrome复制的Outerheml代码
<td>
<input type="checkbox" class="switchery" data-id="2" data-size="xs" checked="" data-switchery="true" style="display: none;"><span class="switchery switchery-xsmall switchery-default" style="background-color: rgb(255, 255, 255); border-color: rgb(223, 223, 223); box-shadow: rgb(223, 223, 223) 0px 0px 0px 0px inset; transition: border 0.4s ease 0s, box-shadow 0.4s ease 0s;"><small style="left: 0px; transition: background-color 0.4s ease 0s, left 0.2s ease 0s;"></small></span>
</td>
我在论坛和Google上进行了很多搜索,但没有找到合适的解决方案。我想知道实现它的登录名。