ajax problem – function on server is not called

My guess is that the shipping method isn’t initialised when you make an ajax call. Try moving your actions directly into your init function. EG: function checkAjax(){ print_r($_POST); exit; } function dhlsweden_shipping_method_init() { //use checkAjax since you don’t have access to your shipping method class. If this is the case then you need to rework … Read more

wp_ajax declaration confusing for Front end

I mean is_admin() is to check if you are on the administration so it will return false, so the code inside won´t be executed on the front-end, won´t it ? When you send an AJAX request using this method, you are sending it to wp-admin/admin-ajax.php, which is in the admin. This is explained in the … Read more

Why, if a function accepts arguments, it fails on ajax calls?

No arguments are passed to the AJAX callback function. Variables passed with the request are available in $_GET or $_POST. So if your function expects an argument, it can’t be used as the hooked callback directly. Your workaround is the correct way to use a function that accepts arguments in an AJAX request.

Load more posts in the same category – Ajax + Timber

I think there is a small correction in your code, you just passing page number but you have pass category ID also. I’ve added data-category attribute in load more button. So your archive.twig should like: <section class=”archive”> <p class=”archive__title h-headline text-size-l”>In the same thematic</p> <div id=”archive__list” class=”archive__list”> <article class=”post”> … </article> </div> </section> {% if … Read more

ajax form is returning the dreaded “[HTTP/1.1 400 Bad Request” and a zero

Your hook name uses an underscore: add_action( ‘wp_ajax_save_form’, ‘save_form’ ); add_action( ‘wp_ajax_nopriv_save_form’, ‘save_form’ ); But your action uses a hyphen. action: ‘save-form’ These need to match: action: ‘save_form’ Also, your AJAX callback appears to be in apps/save_signups.php, but you are only requiring that file inside the admin_menu hook: require_once ( ‘apps/save_signups.php’ ); //process submitted form … Read more

How to make a fetch() POST request to wordpress rest api?

‘X-WP-Nonce’ : Ajax.nonce Was missing that’s why it was giving the error fetch(‘https://mywebsite.online/wp-json/wp/v2/code’, { method: ‘POST’, credentials: ‘same-origin’, headers: new Headers({ ‘Content-Type’: ‘application/json;charset=UTF-8’, ‘X-WP-Nonce’ : Ajax.nonce }), body: JSON.stringify(OurPostData), }).then(response => { console.log(response); return response.json(); });