I make normal requests through AJAX to function.php

if not authorized in admin panel - 400 error crashes

if authorized - then everything is ok

what could be the matter?

action matches everywhere

for example

JS
$(document) .on('click','.To_basket', function() {
  //...
  $.post("/wp-admin/admin-ajax.php", {action:'to_basket', post_id: post_id, size: size})
  .done(function(data) {
   //...
  });
});


function.php

add_action('wp_ajax_to_basket','to_basket');
function to_basket() {
  //...
  wp_die();
}


thank you in advance

1 Answers 1

Who will need:
it was necessary to add action format
add_action('wp_ajax_nopriv__to_basket','_ to_basket');