AJAX Form Button with PHP
06:35 21 Feb 2026

I have an update details form. On click it will update the user details and then run through all events they are registered for, if they no longer meet the age requirements it will make the required changes. This could take some time depending on how many events the user is registered for.

I am trying to make the submit button change from 'Update' to 'Updating please wait...' until the PHP script finishes and returns a value.

My form button code is:

    
     
         

The AJAX code is:
    $("#globalAdminUpdateDetails-form").validate({
        submitHandler: submitForm2  
    }); 

        function submitForm2() {        
        var data = $("#globalAdminUpdateDetails-form").serialize();
        $.ajax({                
            type : 'POST',
            url  : 'response.php?action=globalAdminUpdateDetails',
            data : data,
            beforeSend: function(){ 
                $("#error").fadeOut();
                $("#globalAdminUpdateDetails_button").html('   updating ...');
            },
            success : function(response){           
                if($.trim(response) === "1"){
                    console.log('dddd');                                    
                    $("#globalAdminUpdateDetails-submit").html('Details Updated');
                } 
                if($.trim(response) === "2"){
                    console.log('dddd');                                    
                    $("#globalAdminUpdateDetails-submit").html('Account blocked...');
                    setTimeout(' window.location.href = "accountBlocked.php?errorCode=998990088d9fd8789df9d8d"; ',2000);
                }
                else {                                  
                    $("#error").fadeIn(1000, function(){                        
                        $("#error").html(response).show();
                    });
                }
            }
        });
        return false;                               
    }
html ajax