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.
});
}
});

2 Comments

 Add your comment
  1. kontramundoKontramundo

    Excelente. Thanks

  2. Nice job, Thanks .

Leave a Reply

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

%d bloggers like this: