Ajax form submit within a Post Metabox

Yes you can. Here is a sample code to get you started and some links to follow up. Add a button and a nonce-field to your form <input type=”hidden” name=”my_ajax_nonce” value=”<?php echo wp_create_nonce(‘my_ajax_action’);?>” /> <button id=”submit-my-form” type=”submit”><?php _e(‘Save custom meta data’)?></button> You need to create and register your function you want to execute with your … Read more

WordPress ajax function parameter value not being passed

First of all you should read the codex on AJAX_in_Plugins Secondly you should look at wp_localize_script to get the value for the admin-ajax url to your javascript. $data = array( ‘ajax_url’ => admin_url( ‘admin-ajax.php’ ) ); wp_localize_script( ‘ajax-script’, ‘ajax_object’, $data ); In your javascript, you are then meant to reference the localized data jQuery(“.selectbox”).change(function(){ var … Read more

WordPress ajax get content post id

There are many errors and bad practices in your code. I’ve fixed most of them. Explaining all those here is not possible. I’ve written the explanation as comment where they need to. Please read the whole code and comments attentively- custom.js // Wrap any jQuery code like this. It makes ‘$’ use fullproof // and … Read more

Insert wp_editor on front-end with AJAX?

So, after doing some more digging, I answered my own question by “connecting the dots”, so to speak. There’s a lot of bits and pieces of info on this topic on StackOverflow and StackExchange, but none of them really answered my question. So here is the full working code to loading a wp_editor instance with … Read more

Ajax stops working when logged in?

A few things that I see: There’s a space in your first add_action declaration. Should be add_action(‘wp_ajax_wppl_function’, ‘wppl_function’); Have you declared wppl_function to run it? Have you localized your scripts when logged in? Please review the codex entry on wp_ajax_nopriv (action)

Ensure function has completed before allowing another Ajax call

I usually use CSS classes to control AJAX requests affecting a specific element. This way you can prevent unwanted AJAX requests on that element, while other AJAX requests may still be triggered, being bound to other elements. $(‘.slot’).on(‘click’, ‘a.book’, function(e) { e.preventDefault(); // Check if doing ajax if($(this).hasClass(“doing-ajax”)) return false; $(this).addClass(“doing-ajax”); var user = $(‘#rjb_day’).attr( … Read more

wp_localize_script escaping my url – fix or alternative

wp_localize_script() now uses json_encode() which means a multidimensional array will now work for the passed data. And, HTML entity decoding only applies to the first level of the array. Better is an way to use json and default js possibilities from WP. At first, i add the options from the database via script and json_encode … Read more