Websnippetz

Get cool snippets on php, css, jQuery, Magento and wordpress

Clear form fields after finishing ajax submit using Jquery

Use reset() method to clear form fields after submitting the form via ajax.


$.ajax({
type:"POST",
url:formUrl,
data:formData,
beforeSend:function(){
$('.status').html('<b>Form is being submitted</b>');
},
success:function(data){
$('. status ').html('<b>Thank you!! We have received your form</b>');
},
complete:function(){
$('#form-id').each(function(){
this.reset(); //Here form fields will be cleared.
});
}
});

karthi s

2 thoughts on “Clear form fields after finishing ajax submit using Jquery

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: