title: Wordpress admin ajax.php 400 bad request
body: <p>It turns out that I'm making a Wordpress plugin in which I need to make an AJAX to the file "admin_ajax.php" of Wordpress, but when sending the request, the client gives me error 400 (Bad Request) and I do not understand for what reason.</p>
  
  <p>captures</p>
  
  <p><a href="https://i.stack.imgur.com/5SiDd.png" rel="nofollow noreferrer">https://i.stack.imgur.com/5SiDd.png</a></p>
  
  <p><a href="https://i.stack.imgur.com/tPD6o.png" rel="nofollow noreferrer">https://i.stack.imgur.com/tPD6o.png</a></p>
  
  <p><strong>Javascript:</strong></p>
  
  <pre><code>$.post(window.dibibot.ajax_uri, {
      action: "dibibot_check_message_read",
      to: (window.dibibot.USER_KEYS.split(":")[1]).toString(),
      message_id: JSON.stringify(data.message)
  }, function(response) {
      console.log(response);
  });
  </code></pre>
  
  <p><strong>Ajax php function:</strong></p>
  
  <pre><code>&lt;?php
      function dibibot_check_message_read() {
          global $wpdb;
          $conversation_guid = $_POST['to'];
          $message_id = json_decode($_POST['message_id'], true);
  
          $conversation = $wpdb-&gt;get_var("SELECT metadata FROM " . $wpdb-&gt;prefix . "dibibot_conversations WHERE guid = '".$conversation_guid."'");
          $conversation = maybe_unserialize($conversation);
          for ($j=0; $j &lt; count($message_id) ; $j++) { 
              for ($i=0; $i &lt; count($conversation); $i++) {
                  if($conversation[$i]['id'] == $message_id[$j]) {
                      $conversation[$i]['status'] = 2;
                      break;
                  }
              }
          }
          $result = $wpdb-&gt;update($wpdb-&gt;prefix . 'dibibot_conversations', [ "metadata" =&gt; maybe_serialize($conversation) ], [ "guid" =&gt; $conversation_guid]);
          echo $result ? 1 : 0;
          wp_die(); 
      }
  ?&gt;
  </code></pre>