Advertisement
helgatheviki

Submit Form Via Ajax if Ketchup Validates

Jan 29th, 2012
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.57 KB | None | 0 0
  1. $('#contact-form').submit(function(e) {
  2.        
  3.     //if ketchup validates
  4.     if( $('#contact-form').ketchup("isValid") ) {
  5.        
  6.         //serialize the form data and add an ajax variable
  7.         formData = $(this).serialize() + '&ajax=1';
  8.  
  9.         //send the form via ajax
  10.         $.post($('#contact-form').attr('action'),formData, function(response){
  11.             if(response=='1') {
  12.                 //do some stuff here
  13.                 console.log('success');
  14.             } else {
  15.                 //got some erros
  16.                 var json = jQuery.parseJSON(response);
  17.                 console.log(response);
  18.             }
  19.         });
  20.     }
  21.  
  22.     //don't submit normally
  23.     return false;
  24.  
  25. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement