AJAX with Selectbox Plugins (Select2, Chosen, Selectize)
AJAX with Selectbox Plugins (Select2, Chosen, Selectize)
AJAX with Selectbox Plugins (Select2, Chosen, Selectize)
You are just not using the right function. Try using this: <iframe id=”preview_frame” src=”https://wordpress.stackexchange.com/questions/130860/<?php echo home_url(); ?>”></iframe>
Can’t get query string in ajax call
is_admin() returns true if you’re doing an Ajax request. So this is why my code didn’t work. Instead I’ve done this: add_filter( ‘loop_start’, ‘my_sidebar_widget’, 25 ); function my_sidebar_widget() { if ( is_active_sidebar( ‘my_sidebar’ ) && (defined( ‘DOING_AJAX’ ) && DOING_AJAX ) || !is_admin() ) { echo ‘<div id=”my_sidebar”>’; dynamic_sidebar(‘my_sidebar’); echo ‘</div>’; } } defined( ‘DOING_AJAX’ … Read more
Hyperlink to execute PHP
Plugin constructor called multiple times
Wrap your javascript code with document.ready, and if it works I would suggest going back to putting this in an external file jQuery(document).ready(function(){ jQuery(‘#ajax_form’).on(‘submit’, function(e) { e.preventDefault(); console.log(‘Here’); var form = jQuery(‘#ajax_form’); var data = form.serialize(); data.action = ‘add_word_to_form’ jQuery.post(‘/wp-admin/admin-ajax.php’, data, function(response) { alert(data); }); //return false; }); });
SHORTINIT and sessions
Why you want to use ajax for showing some fields on form in widget? Can’t it be done using simple show hide using jquery. See below. Not tested , just to give insight. HTML <input type=”radio” id=”someradio” /> <div id=”somediv” style=”display:none;”> <input type=”text” name=”<?php $this->get_field_name(‘name’); ?>”> </div> Jquery <script type=”application/javascript”> jQuery(‘#someradio’).on(‘click’,function(){ jQuery(‘#somediv’).toggle(); }); </script>
As czerspalace mentioned you need to pass the action to the .ajax(). One way to do this would be to modify your form: function ea_display_form() { echo ‘ <form id=”eaForm”> <input type=”text” name=”username” /> <input type=”submit” value=”Submit” /> <input type=”hidden” name=”action” value=”ea_ajax_handler” /> </form> ‘; }