Disable Button while AJAX Request

后端 未结 5 2428
旧巷少年郎
旧巷少年郎 2020-12-03 02:33

I\'m trying to disable a button after it\'s clicked. I have tried:

$(\"#ajaxStart\").click(function() {
    $(\"#ajaxStart\").attr(\"disabled\", true);
    $         


        
5条回答
  •  被撕碎了的回忆
    2020-12-03 03:10

    Put $("#ajaxStart").attr("disabled", false); inside the success function:

    $("#ajaxStart").click(function() {
        $("#ajaxStart").attr("disabled", true);
        $.ajax({
            url: 'http://localhost:8080/jQueryTest/test.json',
            data: { 
                action: 'viewRekonInfo'
            },
            type: 'post',
            success: function(response){
                //success process here
                $("#alertContainer").delay(1000).fadeOut(800);
    
                $("#ajaxStart").attr("disabled", false);
            },
            error: errorhandler,
            dataType: 'json'
        });
    });
    

    This will ensure that disable is set to false after the data has loaded... Currently you disable and enable the button in the same click function, ie at the same time.

提交回复
热议问题