How to use AJAX to call php page with parameter

Your code should work just fine, because there’s nothing wrong with it, but… You use relative URL in it You pass loaddata.php?id1= as URL. It’s relative, so it will try to find loaddata.php file in current directory. So if you’re at the home page, then it will try to load that file from root directory. … Read more

Proper way to handle admin-ajax calls

The PHP part of your code looks more or less OK. (There are some security concerns and you shouldn’t echo an array of objects, but you’ll get it when you see it). But your code doesn’t work because of an error in your JS. You should send “action” as data and not as a setting… … Read more

How to do the simplest possible frontend ajax call from a plugin?

From codex: wp_ajax_{$action} and wp_ajax_nopriv{$action} the dinamic part {$action} must be the same name as the function, so instead of: add_action( ‘wp_ajax_the_ajax_hook’, ‘the_action_function’ ); add_action( ‘wp_ajax_nopriv_the_ajax_hook’, ‘the_action_function’ ); do: add_action( ‘wp_ajax_the_action_function’, ‘the_action_function’ ); add_action( ‘wp_ajax_nopriv_the_action_function’, ‘the_action_function’ );

WordPress REST API register_rest_route give a 500 error

Revised answer To other readers, another issue was the OP used the wrong route. So make sure to make the API request to the correct route, which is a combination of the first two parameters for register_rest_route() (namespace + route base). So with register_rest_route( ‘uheme/v1’, ‘/menu’ ), the route is uheme/v1/menu. Additionally: With permalinks enabled, … Read more

ajax request in wordpress

You can take reference from below code. Remove your ajaxrequest.php file, no need of that file because i have added ajaxrequest.php file’s code in active theme’s functions.php file. I have changed ajax url and add js script code in script.js file. I have tested and it is working for me. let me know if this … Read more