Advertisement
Guest User

ajax form

a guest
Apr 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             $('body').on('submit','#contact-form', function(event){
  2.                 event.preventDefault();
  3.  
  4.                 var form = $(this);
  5.  
  6.                 $.ajax({
  7.                    'method': 'post', // use post since you use $_POST in php file to process data
  8.                    'action': '/' + $(form).attr('action'), // url to send a form data
  9.                    'data': $(form).serialize(), // serialized form data
  10.                 }).done(function(response){
  11.                     // to do something with response text
  12.                 });
  13.                
  14.             });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement