• 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 topic was modified 5 years, 9 months ago by d555555.
    • This topic was modified 5 years, 9 months ago by d555555.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Ajax call works for logged in users and returns “Bad Request” for guests’ is closed to new replies.