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…

5 years ago

jQuery library Introduction

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

5 years ago

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

HTML:- [crayon-662edad2eb4f5697359916/] CSS:- [crayon-662edad2eb4fb494060878/] JavaScript:- [crayon-662edad2eb4fd987857178/]  

5 years ago

Customize Input Box using jQuery

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

5 years ago

JavaScript simple form validation with example

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

5 years ago

Clear the browser cache of CSS or JavaScript Using Javascript

[crayon-662edad2eb971506783068/]  

5 years ago