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


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.

Read Also:  jquery Increment Animating Numbers Counting Up Example

<!DOCTYPE html>
        <title>jquery disable button after click submit form example</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
        <p>Click the submit button below to this disable it!</p>
        <button id="mybutton_submit">Submite</button>
            //Add a  button click event handler to each our button.
            $('#mybutton_submit').on('click', function(){
                //here Disable each  button set attribues
                $('#mybutton_submit').attr("disabled", true);
                var seturl = window.location.href;
                    url: seturl,
                    success: function(data){
                        //The Ajax request was a success.
                        //Do here code enable or disable something in here.
                    complete: function(){
                        //Ajax  call request is finished or done, so we can enable my submit button
                        //the button again call.
                        $('#mybutton_submit').attr("disabled", false);


how to disable or enable button using jquery Ajax Call

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

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.

Read Also:  Simple JavaScript Get current url Example

var fewSeconds = 5;
    // simple Ajax request
    var btnadd = $(this);
    btnadd.prop('disabled', true);
        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

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Get Table name From Model using Laravel 5.7 Example
  2. Read Also:  How to Open URL in New Tab using JavaScript
  3. Read Also:  how to calculate percentage discount using calculator?
  4. Read Also:  Simple Hello World Example using Angular
  5. Read Also:  jQuery Enable Disable Submit Button Example
  6. Read Also:  jquery disable button
  7. Read Also:  jQuery Disable Button After Click Example
  8. Read Also:  jQuery AJAX Pagination in PHP Without Page Refresh Example
  9. Read Also:  javascript get element by class
  10. Read Also:  how to upload project file to github using command line?