Categories: Snippets

Simple Ajax Call

var form = $('#main-contact-form');

 form.submit(function(event){

  event.preventDefault();

  var form_status = $('<div class="form_status"></div>');

  $.ajax({

   url: $(this).attr('action'),
   method : 'POST',
   data : $(this).serialize(),
   beforeSend: function(){

    form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn() );

   }

  }).done(function(data){

   form_status.html('<p class="text-success">Thank you for contact us. As early as possible  we will contact you</p>').delay(3000).fadeOut();
   $(this).reset();
  });

 });

 

Share

Recent Posts

Selecting Elements in jQuery (jQuery Selectors)

To collect a group of elements, we pass the selector to the jQuery function using…

7 years ago

jQuery library Introduction

jQuery is a lightweight, "write less, do more", JavaScript library. The purpose of jQuery is…

7 years ago

Adjust li width fit with ul width of the outer div/body

HTML:- [crayon-6928590372559140707047/] CSS:- [crayon-6928590372562629553094/] JavaScript:- [crayon-6928590372565409354800/]  

7 years ago

Customize Input Box using jQuery

Prevent users typing special characters in text box, textarea, etc. [crayon-6928590372734169052534/] ^[a-zA-Z]+$ Alphabets ^[a-zA-Z\s]+$ Alphabets…

7 years ago

JavaScript simple form validation with example

Any interactive web site has form input - a place where the users input different…

7 years ago

Clear the browser cache of CSS or JavaScript Using Javascript

[crayon-6928590372bbb034459530/]  

7 years ago