Q:

Calling beforeSend in ajax success

How to call beforeSend only in success? Right now, my button is also changing text to "Working" when error comes into ajax call.
  success: function(data) {            
            alert("operation successful");                    
         },
  beforeSend: function() {
            btnSubmit.val("Working...");
         },
  error: function(response) {                   
            alert("something went wrong");                  
         }

A:

Use "complete" to alter the button text
complete: A function to be called when the request finishes (after success and error callbacks are executed)

 success: function(data) {
            alert("operation successful");
         },
  beforeSend: function() {
            btnSubmit.val("Working...");
         },
  error: function(response) {
            alert("something went wrong");
         },
  complete:function() {
            btnSubmit.val("Done");
         }
}

