Hello,
HTTP 400 error on WordPress Ajax call is typically an error due to bad action declaration. In your case, I can see that you use 2 different callback functions acfe_buttons_ajax & financial_buttons_ajax. One (or both) are most likely undefined, that’s why you get the 400 error code.
Here is the WordPress documentation on ajax: https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action)
Have a nice day!
Regards.
Thanks, that was an issue, but only because when I copied over the code here I mistakenly didn’t change both action function names. I did however figure out the issue with the 400 error, it was that I was including the function only on the post.php edit page, it also needed to be included while doing ajax. (|| wp_doing_ajax()), and I am now getting a response.
I am now having issues with getting the response to the success callback.
Here is the code I have:
function acfe_buttons_ajax() {
ob_start();
echo 'Results';
$result = ob_get_contents();
ob_end_clean();
return $result;
wp_die();
}
add_action('wp_ajax_acfe/fields/button', 'acfe_buttons_ajax');
add_action('wp_ajax_nopriv_acfe/fields/button', 'acfe_buttons_ajax');
and:
acf.addAction('acfe/fields/button/ajax_success', function(response, $el){
alert(response);
});
The js does the alert, but just alerts “0”. Any thoughts?
The .js is enqueued in functions.php like:
function agency_enqueue($hook) {
if ( 'post.php' != $hook ) {
return;
}
wp_enqueue_script( 'agency_js', get_stylesheet_directory_uri() . '/js/admin-agency.js', array('jquery'), null, true );
}
add_action( 'admin_enqueue_scripts', 'agency_enqueue' );
Nevermind, I figured this out, thanks so much for you efforts and wonderful extension to ACF!
Hello,
Yeah you need to echo 'Results'; and not return it.
I’m glad you enjoy ACF Extended! BTW, if you would like to support me, feel free to write a review, it always helps! 🙂
Have a nice day,
Regards.