Php ajax没有';t实时更新元素
查看以下进行ajax调用的jQuery.on()方法:Php ajax没有';t实时更新元素,php,jquery,mysql,ajax,Php,Jquery,Mysql,Ajax,查看以下进行ajax调用的jQuery.on()方法: $('tbody').on('click', 'button',function() { var updInfo = {}; updInfo.unqid = $(this).closest('tr').attr('unqid'); $.ajax({ url: "http://localhost/ReceptionVisitorKiosk/baseco
$('tbody').on('click', 'button',function() {
var updInfo = {};
updInfo.unqid = $(this).closest('tr').attr('unqid');
$.ajax({
url: "http://localhost/ReceptionVisitorKiosk/basecoat/server/checkout.php",
data: updInfo,
type: 'POST',
dataType: 'json',
}).done(function(data) {
$(this).closest('tr').removeClass('active-visitor').addClass('inactive-visitor');
$(this).addClass('glyphicon glyphicon-ok');
console.log(data);
}).fail(function(status,errorThrown){
console.log(errorThrown);
}).always(function(xhr,status){
console.log("The request 2 is complete");
}); // End AJAX call
});
当用户单击按钮时,将调用php脚本并更新数据库。但是,我们应该期望.done()随后删除类并将其添加到$(this)
。我在浏览器或f12>检查器视图中看不到这种情况
在整个页面刷新时,类更改是可见的
console.log(这个)
应该能揭示问题所在…@RolandStarke:或者更好,与其在黑暗中用console.log
torch蹒跚而行,不如用浏览器内置的功能齐全的调试器打开灯。;-)在done
回调中的this
的重复不是this
在on
回调中的内容。请参阅该问题的答案以了解解释和选项。例如,您可以在ajax调用之前执行var$btn=$(this)
,然后在页面加载时使用$btn
而不是$(this)
处理程序中的$(this)
。。检查该类的可见性并将其隐藏。感谢t.j.Crowder您的评论解决了我的问题