Reputation: 3697
I have a basic form which I am submitting via AJAX. I want to add a class to my form whilst the AJAX request is being sent so that I can style it slightly differently.
Is there a way to hook into AJAX whilst submitting and use jQuery addClass? Here is my AJAX script:
jQuery(document).ready(function() {
jQuery('#pay_what_you_want_form').submit(function() {
jQuery(this).ajaxSubmit({
success: function(){
alert('Settings have been updated');
},
timeout: 5000
});
return false;
});
});
I would like to add the class "loading" to the form with ID #pay_what_you_want_form
Upvotes: 0
Views: 112
Reputation: 8101
Yes can add class while submitting:
jQuery('#pay_what_you_want_form').submit(function() {
jQuery('#pay_what_you_want_form').addClass("loading"); // add class here
jQuery(this).ajaxSubmit({
success: function(){
alert('Settings have been updated');
jQuery('#pay_what_you_want_form').removeClass("loading"); // Remove class here as form is submitted now
},
timeout: 5000
});
return false;
});
Upvotes: 2