wp_ajax is not calling the action

if the request is from an unauthenticated user, you should use wp_ajax_nopriv_(action) to call the function, which in your case is: add_action(‘wp_ajax_nopriv_cpm_add_update’, array($this,’edit_added_people’));

Can’t load search results with ajax

The JavaScript should be: <script> jQuery( document ).ready(function ( $ ) { $( “#searchform” ).on( “submit”, function ( ev ) { ev.preventDefault(); $.post( “<?php echo admin_url( ‘admin-ajax.php’ ) ?>”, { action: “wpa56343_search”, search: $( “#s” ).val() }, function ( response ) { $( “body” ).append( response ); } ); }); }); </script> And the AJAX … Read more

adding ajax load more to display images from meta box

It can be done just following regular way to use Ajax in WordPress. https://codex.wordpress.org/AJAX_in_Plugins First register a script file and also create an AJAX Call. wp_enqueue_script( ‘meta-ajaxscript’, get_stylesheet_directory_uri() . ‘/js/ajax-init.js’, array( ‘jquery’ ), ”, true ); wp_localize_script( ‘meta-ajaxscript’, ‘ajaxMeta’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ) )); Second, Wrap your metadata with a parent element by … Read more

wp_ajax action is not run when ajax trigger

I’ve tested your code and it works perfectly. I’ve just declared the dependencies for the JavaScript, so it is loaded correctly after jQuery. This is how I’ve tested it: functions.php function my_resource() { wp_enqueue_script(‘my-jquery’,get_template_directory_uri().’/jqfunctions.js’, array(‘jquery’)); wp_localize_script( ‘my-jquery’, ‘myback’, array(‘ajax_url’ => admin_url( ‘admin-ajax.php’ ))); } add_action(‘wp_enqueue_scripts’, ‘my_resource’); function getsomething(){ wp_send_json_error(‘hey’); } add_action(‘wp_ajax_nopriv_getsomething’, ‘getsomething’); add_action(‘wp_ajax_getsomething’, ‘getsomething’); jqfunctions.js … Read more

Can’t retrieve any content from Ajax-loaded page

The correct answer is to just do AJAX the right way. Enqueue your script and localize it to add the path to admin-ajax.php: function wpd209588(){ wp_enqueue_script( ‘wpd209588_script’, get_template_directory_uri() . ‘/js/your-script.js?ver=1.0’, array( ‘jquery’ ) ); wp_localize_script( ‘wpd209588_script’, ‘WPaAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ) ) ); } add_action( ‘wp_enqueue_scripts’, ‘wpd209588_scripts’ ); In your-script.js, do your AJAX … Read more

How to create a form button that executes a function?

This is a simple example of rendering some items on the front-end that use AJAX to trigger changes in the back-end and update the UI from that response. There are other examples that enqueue scripts so just read up on AJAX and consider this a high level view. REGISTER AJAX/SCRIPTS/CSS add_action(‘init’, function () { // … Read more

What WP-API authentication method should I use to interact with anonymous / not-logged visitors?

In WP REST API v2 use the permission_callback found in the Adding Custom Endpoints Docs. <?php add_action( ‘rest_api_init’, function () { register_rest_route( ‘myplugin/v2’, ‘/author/(?P<id>\d+)’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘my_awesome_func’, ‘args’ => array( ‘id’ => array( ‘validate_callback’ => ‘is_numeric’ ), ), ‘permission_callback’ => function (WP_REST_Request $request) { if ( current_user_can( ‘edit_others_posts’ ) ) { … Read more

Multiple AJAX requests using the same ajax_object.ajaxurl

To clarify your doubt you localized variable will contains the same values until it is overriden. In your case EMX.ajaxurl will be available throught the script. Ajax not happening at your intended event might be due to not executing the ajax function but definetly not due to EMX.ajaxurl. EMX.ajaxurl will contain the ajax url. EMX.ajaxurl … Read more