Ajax Request not coming back to class
Ajax Request not coming back to class
Ajax Request not coming back to class
The problem is your action names don’t match In your frontend code: ?action=find_coach’; But in your backend code: add_action(‘wp_ajax_search_coach’, ‘searchLifeCoach’); add_action(‘wp_ajax_nopriv_search_coach’, ‘searchLifeCoach’); search_coach != find_coach, they have to match. Note that if this code used the REST API, it would have given a 404 and stated the problem in human readable language, e.g. { “code”:”rest_no_route”, … Read more
I tested that code like this: wp_enqueue_script(‘jquery’); wp_localize_script( ‘jquery’, ‘MS_Ajax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ), ‘nextNonce’ => wp_create_nonce( ‘myajax-next-nonce’ )) ); And it works but throws a Notice. It should be hooked to wp_enqueue_scripts like: function my_enqueue_scripts() { wp_enqueue_script(‘jquery’); wp_localize_script( ‘jquery’, ‘MS_Ajax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ), ‘nextNonce’ => wp_create_nonce( ‘myajax-next-nonce’ )) ); … Read more
I’m not good with English, but the answer is that the editor class calls the scripts needed in the admin footer (wp-includes/class-wp-editor.php line 160) : add_action( ‘admin_print_footer_scripts’, array( __CLASS__, ‘editor_js’), 50 ); add_action( ‘admin_footer’, array( __CLASS__, ‘enqueue_scripts’), 1 ); So when you call the wp_editor function in your ajax, the scripts aren’t printed with it, … Read more
Below function works for me by adding !defined(‘DOING_AJAX’) in condition. function custom_blockusers_init() { if ( is_admin() && !defined(‘DOING_AJAX’) && ( current_user_can(‘usercrp’) || current_user_can(‘userpcp’) || current_user_can(‘subscriber’) || current_user_can(‘contributor’) || current_user_can(‘editor’))) { session_destroy(); wp_logout(); wp_redirect( home_url() ); exit; } } add_action( ‘init’, ‘custom_blockusers_init’ );
I’d use the default WP AJAX API so WP can handle all the authentication for you. You’d add a function and an action to trigger it: function wpse_314311_get_quote() { // get quote from db // print json to client exit; } add_action( ‘wp_ajax_get_quote’, ‘wpse_314311_get_quote’ ); That way, WP will make sure that only logged in … Read more
Okay so NOW I have the entire solution. It was two things: Caching was the first part of the issue. Cleared cache, deactivated caching plugin for the time-being. The second, less obvious issue was that, for NOT logged-in users, the response from the AJAX call was returning the entire HTML document in the response area. … Read more
You are using the system cron to trigger a function hooked into the AJAX API, not, as your title reads, using “admin-ajax.php to run a real cron job”. You are doing exactly the opposite of what you wrote in the title (I’d advise editing that). Yes, that is perfectly fine. I have advised using the … Read more
Admin Ajax always return 0 on form submit
wp_remote_get() to get AJAX url /wp-admin/admin-ajax.php