$(document).ready( function(){ $( 'form.form-partner' ).on( 'submit', function( e ) { e.preventDefault(); if(!$('span.field__error-msg').length > 0 ){ var form = $( this ); var data = new FormData( this ); data.append('action', 'action_partner') $.ajax({ type: 'POST', url: '/wp-admin/admin-ajax.php', xhrFields: { withCredentials: true }, data: data, processData: false, contentType: false, dataType: 'json', success: function( response ) { console.log(response); if ( 'success' == response.status ) { // alert("success"); $("form").remove(); $("p").remove(); $(".form-thankyou").show(); } else { // alert("No success"); } } }).done( function( response ) { //alert("Done"); }); }else{ console.log("tester"); } }); });