From 34d3cc62c83f01d742f1ee5ab9ff0fcd14d04c05 Mon Sep 17 00:00:00 2001 From: Milen Petrinski Date: Wed, 28 Aug 2019 20:49:40 +0300 Subject: [PATCH] Simplify form data serialization when submitting form with AJAX. --- public/js/gdrf-public.js | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/public/js/gdrf-public.js b/public/js/gdrf-public.js index ffa6ce0..5990211 100644 --- a/public/js/gdrf-public.js +++ b/public/js/gdrf-public.js @@ -1,28 +1,13 @@ ( function( $ ) { 'use strict'; - + jQuery(document).ready(function() { $( '#gdrf-form' ).on( 'submit', function( event ) { - + event.preventDefault(); - - var data_type = ''; - if ( $( 'input[name=gdrf_data_type]' ).is( ':checkbox' ) ) { - data_type = $( 'input[name=gdrf_data_type]:checked', '#gdrf-form').val(); - } else { - data_type = $( 'input[name=gdrf_data_type]', '#gdrf-form').val(); - } - - var button = $( '#gdrf-submit-button' ), - data = { - 'action': 'gdrf_data_request', - 'gdrf_data_type' : data_type, - 'gdrf_data_human_key': $( '#gdrf_data_human_key' ).val(), - 'gdrf_data_email': $( '#gdrf_data_email' ).val(), - 'gdrf_data_human': $( '#gdrf_data_human' ).val(), - 'gdrf_data_nonce': $( '#gdrf_data_nonce' ).val(), - }; + + var data = $( this ).serialize(); $( '.gdrf-errors' ).remove(); $( '.gdrf-success' ).remove();