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
1 Answer
Reset to default 0The action for non-logged in users is wp_ajax_nopriv_{$action}
.