Disable submit button until Ajax Completes Example

Disable submit button until Ajax Completes Example

Welcome to the In Pakainfo.com website! You will Step By Step learn web programming, easy and very fun. This website allmost provides you with a complete web programming tutorial presented in an easy-to-follow manner. Each web programming tutorial has all the practical examples with web programming script and screenshots available.For

index.html

This is a short Post on how to my submit button disable a button until an call the Ajax request has been completed or done.



    
        jquery disable button after click submit form example
        
        
        
    
    
        

Click the submit button below to this disable it!

how to disable or enable button using jquery Ajax Call

$("input[name=groups-name]").blur(function () {
		$('#loading-div').show();
		$('#findgroups').hide();
		var pclass=$(this).attr('class').split(' ')[1];
	   $.ajax({
			type: 'POST',
			url: 'php/getid.php',
			dataType: 'json',
			data: { 'name' : $(this).val() },
			success : function(result){
					$('#loading-div').hide();
					$('#findgroups').show();
					if(pclass=='groups')
					{
						var result=result+"/"+pclass+"/";
					}
					
					$('input[name=groups-name]').attr('format',result);
				
			},error: function (jqXHR, exception) {
				$('#findgroups').show();
				$('#loading-div').html("Please Enter Valid keywords");
			}
		});
	});
});

jquery disable button after click for 5 seconds Example

jquery call the ajax after the setTimeout function call to the simple 5 seconds button automatically enable.

var fewSeconds = 5;
$('#btnadd').click(function(){
    // simple Ajax request
    var btnadd = $(this);
    btnadd.prop('disabled', true);
    setTimeout(function(){
        btnadd.prop('disabled', false);
    }, fewSeconds*1000);
});

Example 1

Example 2

jquery disable button after click submit form | how to disable a button in jquery | jquery disable button after click for 5 seconds | jquery ajax get example

Leave a Comment