フォームを使用する代わりに更新関数を作成しようとしています。私はdata- *属性とajaxを使用します。値を更新した後にボタンが発射されないようにしたいのですが、私のボタンの入力(数値)とdata- *属性の値がすでに同じです。私はあなたが私を助けてくれることを願っています。 success:
ハンドラでajaxとdata- *属性を使用してボタンを更新します
$('body').on('click', '.btn-edituser', function(){
var button = $(this);
var upval = button.parent().prev().find('.data-avail').val();//get the value of the input(number)
var updateId = button.data('updateid');// this is the user id to be pass on to the php file
var tempAv = button.data('tempavail'); //doesn't get the new values after updating this is my PROBLEM
if(upval != tempAv){ //check if the input(number) has been changes value/doesn't have the same value with the data attribute (temporary)
button.addClass('disabled');
button.html('<i class="fa fa-refresh fa-spin"></i> Updating...');
$.ajax({
url:'./inc/update-avail.php',
type: 'POST',
data:{upval:upval, updateId:updateId},
success:function(data){
button.removeClass('disabled');
button.attr('data-tempavail', upval); //update the data attribute (temporary)
button.removeClass('btn-info').addClass('btn-success').html('<i class="fa fa-check"></i> Success');
setTimeout(function(){
button.removeClass('btn-success').addClass('btn-info').html('<i class="fa fa-pencil"></i> Edit');
}, 1000);
}
});
} });
変更button.attr。 button.attr( 'data-tempavail'、tempAv) – coder