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…

6 years ago

jQuery library Introduction

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

6 years ago

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

HTML:- [crayon-67ae035d21cbd448332931/] CSS:- [crayon-67ae035d21cc4951348956/] JavaScript:- [crayon-67ae035d21cc6924037992/]  

6 years ago

Customize Input Box using jQuery

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

6 years ago

JavaScript simple form validation with example

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

6 years ago

Clear the browser cache of CSS or JavaScript Using Javascript

[crayon-67ae035d22505821610321/]  

6 years ago