$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>actions - Ajax call works for logged in users and returns "Bad Request" for guests|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

actions - Ajax call works for logged in users and returns "Bad Request" for guests

matteradmin11PV0评论
This question already has an answer here: simple wordpress ajax plugin not working when not logged in (1 answer) Closed 6 years ago.

I have a WordPress site that uses ajax to submit a form on the Front-end.

When the form is submitted by a logged-in user, all works fine. When the form is submitted by not-logged-in user, I get a "Bad Request" error.

Here is my code:

JS:

$('form').on('submit', function (e) {
    e.preventDefault();

    // Submit the POST request
    $.ajax({
        url: jsobject.ajaxurl,
        method: 'POST',
        data: {
            action: 'fe_submit_form'
        }
    });
});

PHP:

function fe_submit_form() {
    ...
}
add_action( 'wp_ajax_fe_submit_form', 'fe_submit_form' );

When the user is logged in, all works fine. When the user is not logged it, I never go inside of the "fe_submit_form" php function.

Any ideas?

This question already has an answer here: simple wordpress ajax plugin not working when not logged in (1 answer) Closed 6 years ago.

I have a WordPress site that uses ajax to submit a form on the Front-end.

When the form is submitted by a logged-in user, all works fine. When the form is submitted by not-logged-in user, I get a "Bad Request" error.

Here is my code:

JS:

$('form').on('submit', function (e) {
    e.preventDefault();

    // Submit the POST request
    $.ajax({
        url: jsobject.ajaxurl,
        method: 'POST',
        data: {
            action: 'fe_submit_form'
        }
    });
});

PHP:

function fe_submit_form() {
    ...
}
add_action( 'wp_ajax_fe_submit_form', 'fe_submit_form' );

When the user is logged in, all works fine. When the user is not logged it, I never go inside of the "fe_submit_form" php function.

Any ideas?

Share Improve this question asked Feb 25, 2019 at 21:21 ddd555ddd555 31 bronze badge 1
  • The following question may point you in the right direction: wordpress.stackexchange/questions/280607/… . Also, you should review the WordPress documentation on AJAX codex.wordpress/… – czerspalace Commented Feb 25, 2019 at 22:30
Add a comment  | 

1 Answer 1

Reset to default 0

The action for non-logged in users is wp_ajax_nopriv_{$action}.

Post a comment

comment list (0)

  1. No comments so far