0

次の方法を試しました。

1) 表示/非表示

$('button').ajaxStart(function() {
 $(this).hide();
});
$('button').ajaxStop(function() {
 $(this).show();
});

2) 表示/非表示

$('button').ajaxStart(function() {
 $(this).css({visibility, 'hidden'});
});
$('button').ajaxStop(function() {
 $(this).css({visibility, 'visible'});
});

3) クラスの追加/削除

$('button').ajaxStart(function() {
 $(this).addClass('invisible');
});
$('button').ajaxStop(function() {
 $(this).removeClass('invisible');
});

4) 有効化/無効化

$('button').ajaxStart(function() {
 $(this).attr('disabled','disabled')
});
$('button').ajaxStop(function() {
 $(this).removeAttr('disabled');
});

これまでのところ、Show/Hide メソッドだけが 1 秒未満で実行できる十分な応答性を備えています。残りは 1 ~ 2 秒かかりましたが、これは非常に長い時間です。ただし、ボタンを表示したいのですが、顕著な CSS の変更を加えて無効にします。送信ボタンを一時的に有効または無効にする、より応答性の高い方法はありますか?

4

1 に答える 1

0

これを試して:

$("button").click(function() {

    // disable the submit button before the ajax call...
    $(this).attr('disabled','disabled');
    $.ajax({
        url: 'yoururl.html',
        data: {},
        type: 'post',
        success: function(response){
            // enable the submit button after ajax call success...
            $(this).removeAttr('disabled');
        },
        error: function(){
            // error process here
            $(this).removeAttr('disabled');
        },
        dataType: 'json'
    });
});
于 2012-12-23T13:11:14.507 に答える