{"id":6068137,"date":"2015-04-28T05:23:39","date_gmt":"2015-04-28T05:23:39","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/adding-jquery-2\/"},"modified":"2016-08-24T15:17:17","modified_gmt":"2016-08-24T15:17:17","slug":"adding-jquery-2","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/adding-jquery-2\/","title":{"rendered":"Adding jQuery"},"content":{"rendered":"<p>Hey there..!<\/p>\n<p>Really nice plugin, thanks for sharing it !<\/p>\n<p>As you know, the less inline &#8211; the better..<\/p>\n<p>Please check this out : )<\/p>\n<p>Thank you and best regards<\/p>\n<p>PHP Part inside your ajax.php<\/p>\n<pre><code>\/\/ Enqueue Script for Newsletter\nif ( ! function_exists( &#039;epm_mailchimp_footer_js&#039; ) )\n{\n\tadd_action( &#039;wp_enqueue_scripts&#039;, &#039;epm_mailchimp_footer_js&#039; );\n\tfunction epm_mailchimp_footer_js()\n\t{\n\t\twp_enqueue_script(&#039;newsletter-script&#039;, get_stylesheet_directory_uri() . &#039;\/js\/newsletter.js&#039;, array(&#039;jquery&#039;),&#039;1.0&#039;, true);\n\t\twp_localize_script(&#039;newsletter-script&#039;, &#039;epNewsletterVars&#039;, array(\n\t\t\t\t&#039;ajaxURI&#039; =&gt; admin_url(&#039;admin-ajax.php&#039;),\n\t\t\t\t&#039;successEvent&#039; =&gt; do_action(&#039;epm_jquery_ajax_success_event&#039;)\n\t\t\t)\n\t\t);\n\t}\n}<\/code><\/pre>\n<p>jQuery-Part inside childthemes js folder<\/p>\n<pre><code>jQuery(window).load(function() {\n\tjQuery(&#039;.epm-submit-chimp&#039;).click(function() {\nalert(bbNewsletterVars.ajaxURI);\n\t\t\/\/get form values\n\t\tvar epm_form = jQuery(this);\n\t\tvar epm_list_id = jQuery(epm_form).parent().find(&#039;#epm_list_id&#039;).val();\n\t\tvar epm_firstname = jQuery(epm_form).parent().find(&#039;#epm-first-name&#039;).val();\n\t\tvar epm_lastname = jQuery(epm_form).parent().find(&#039;#epm-last-name&#039;).val();\n\t\tvar epm_email = jQuery(epm_form).parent().find(&#039;#epm-email&#039;).val();\n\n\t\t\/\/change submit button text\n\t\tvar submit_wait_text = jQuery(this).data(&#039;wait-text&#039;);\n\t\tvar submit_orig_text = jQuery(this).val();\n\t\tjQuery(this).val(submit_wait_text);\n\n\t\tjQuery.ajax({\n\t\t\ttype: &#039;POST&#039;,\n\t\t\tcontext: this,\n\t\t\turl: epNewsletterVars.ajaxURI,\n\t\t\tdata: {\n\t\t\t\taction: &#039;epm_mailchimp_submit_to_list&#039;,\n\t\t\t\tepm_list_id: epm_list_id,\n\t\t\t\tepm_firstname: epm_firstname,\n\t\t\t\tepm_lastname: epm_lastname,\n\t\t\t\tepm_email: epm_email\n\t\t\t},\n\t\t\tsuccess: function(data, textStatus, XMLHttpRequest){\n\t\t\t\tvar epm_ajax_response = jQuery(data);\n\t\t\t\tjQuery(epm_form).parent().find(&#039;.epm-message&#039;).remove(); \/\/ remove existing messages on re-submission\n\t\t\t\tjQuery(epm_form).parent().prepend(epm_ajax_response);\n\t\t\t\tjQuery(epm_form).val(submit_orig_text); \/\/ restore submit button text\n\t\t\t\tepNewsletterVars.successEvent;\n\t\t\t},\n\t\t\terror: function(XMLHttpRequest, textStatus, errorThrown){\n\t\t\t\talert(&#039;Something Went Wrong!&#039;);\n\t\t\t}\n\t\t});\n\t\treturn false;\n\n\t});\n});<\/code><\/pre>\n<p>https:\/\/wordpress.org\/plugins\/easy-peasy-mailchimp-ajax-form\/<\/p>\n","protected":false},"template":"","class_list":["post-6068137","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6068137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6068137\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=6068137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}