AJAX Request in plugin end login

I embed a form and a javascript file into a plugin.


wp_enqueue_script(‘jquery_s’, plugin_dir_url(__FILE__) . ‘js/jquery.js’, array(‘jquery’));
add_action( ‘wp_ajax_ob_form’, ‘ob_form’ );

function ob_form() {
// do some stuff or do nothing

function html_form_code() {
echo ‘
<idv clas=”content”>
<form action=”‘.admin_url(‘admin-ajax.php’).'” method=”post” class=”wordpress-ajax-form”>
<input type=”hidden” name=”action” value=”ob_form”>
<input type=”hidden” name=”id” value=”‘.$id.'”>



jQuery(document).ready(function($) {
$(‘.wordpress-ajax-form’ ).on(‘submit’, function(e) {
var $form = $(this);

$.post($form.attr(‘action’), $form.serialize(), function(data) {
// do something
}, ‘json’);
return false;

The AJAX request runs smoothly but logs me out automatically.
The debug logfile shows no errors.

How can I prevent the logout?

Read more here:: AJAX Request in plugin end login

Leave a Reply

Your email address will not be published. Required fields are marked *