【发布时间】:2022-01-08 02:04:19
【问题描述】:
有没有办法在每次调用 JQuery Ajax 函数后重置应用程序状态?
我正在开发一个小应用程序:用户单击一个按钮来调用一个函数。但是之后,当用户想要点击其他按钮来调用相同的功能时,第一个点击按钮的动态ID仍然存在,所以其他按钮不能再被寻址了。
代码:
$('#submitComment').on('click', function(){
var id = $(this).data('id');
var thiselement = $(this);
$.ajax({
url: 'includes/updateicon.php',
type: 'POST',
data: {id:id},
dataType: 'html',
success: function(data){
if (data) {
$('#submitComment').attr("disabled", true);
$('#customComment').val("");
$('#updatedicon-'+id).html("DONE").removeClass('badge-danger').addClass('badge badge-success');
# CODE HERE TO RESET THE STATE OF THE APP
}
else {
$('#customContent').load("custom/static/error.html");
}
},
error: function(jqXHR, textStatus, errorThrown){
$('#customContent').html("There was an Error about getting the Content:" + errorThrown);
}
});
});
【问题讨论】:
标签: javascript jquery ajax