Adding jQuery
-
Hey there..!
Really nice plugin, thanks for sharing it !
As you know, the less inline – the better..
Please check this out : )
Thank you and best regards
PHP Part inside your ajax.php
// Enqueue Script for Newsletter if ( ! function_exists( 'epm_mailchimp_footer_js' ) ) { add_action( 'wp_enqueue_scripts', 'epm_mailchimp_footer_js' ); function epm_mailchimp_footer_js() { wp_enqueue_script('newsletter-script', get_stylesheet_directory_uri() . '/js/newsletter.js', array('jquery'),'1.0', true); wp_localize_script('newsletter-script', 'epNewsletterVars', array( 'ajaxURI' => admin_url('admin-ajax.php'), 'successEvent' => do_action('epm_jquery_ajax_success_event') ) ); } }
jQuery-Part inside childthemes js folder
jQuery(window).load(function() { jQuery('.epm-submit-chimp').click(function() { alert(bbNewsletterVars.ajaxURI); //get form values var epm_form = jQuery(this); var epm_list_id = jQuery(epm_form).parent().find('#epm_list_id').val(); var epm_firstname = jQuery(epm_form).parent().find('#epm-first-name').val(); var epm_lastname = jQuery(epm_form).parent().find('#epm-last-name').val(); var epm_email = jQuery(epm_form).parent().find('#epm-email').val(); //change submit button text var submit_wait_text = jQuery(this).data('wait-text'); var submit_orig_text = jQuery(this).val(); jQuery(this).val(submit_wait_text); jQuery.ajax({ type: 'POST', context: this, url: epNewsletterVars.ajaxURI, data: { action: 'epm_mailchimp_submit_to_list', epm_list_id: epm_list_id, epm_firstname: epm_firstname, epm_lastname: epm_lastname, epm_email: epm_email }, success: function(data, textStatus, XMLHttpRequest){ var epm_ajax_response = jQuery(data); jQuery(epm_form).parent().find('.epm-message').remove(); // remove existing messages on re-submission jQuery(epm_form).parent().prepend(epm_ajax_response); jQuery(epm_form).val(submit_orig_text); // restore submit button text epNewsletterVars.successEvent; }, error: function(XMLHttpRequest, textStatus, errorThrown){ alert('Something Went Wrong!'); } }); return false; }); });
https://www.ads-software.com/plugins/easy-peasy-mailchimp-ajax-form/
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Adding jQuery’ is closed to new replies.