title: WordPress ajax returns 404 bad request?
body: <p>The error is below</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>POST http://localhost/...../wp-admin/admin-ajax.php 400 (Bad Request)
  
  send @ load-scripts.php?c=1…e,utils&amp;ver=4.9.8:4 ajax @ load-scripts.php?c=1…e,utils&amp;ver=4.9.8:4 (anonymous) @ my-ajax-handler.js?ver=0.1.0:24 i @ load-scripts.php?c=1…e,utils&amp;ver=4.9.8:2 fireWith @ load-scripts.php?c=1…e,utils&amp;ver=4.9.8:2 ready @ load-scripts.php?c=1…e,utils&amp;ver=4.9.8:2
  K @ load-scripts.php?c=1…e,utils&amp;ver=4.9.8:2</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>                $.ajax({
                      type: "POST",
                      url    : my_ajax_handler_var.ajaxurl,
                      
                      data   : {
                           action: 'rc_generate_pa'// "wp_ajax_*" action hook
                      },
                      contentType: "application/json; charset=utf-8",
                      dataType: "json"
                      ,success:function(data) {
                           //This outputs the result of the ajax request
                          var pass = JSON.parse( data );
                          $('#p').val(data);
                          alert( JSON.parse(data));
                      },
                      error: function(errorThrown){
                          console.log(errorThrown);
                      }
                  })
  //                .done( function( response ) {
  //                    var pass = response;
  //                    $('#p').val(pass);
  //                })
                  .fail( function() {
                      console.log("failed");
                  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>PHP code for enqueing script and handling request </p>
  
  <pre><code>add_action('admin_enqueue_scripts', 'enqueue_st_page_scripts');
   function enqueue_st_page_scripts() {       
  wp_register_script('my-ajax-handler', $plugin_url .'js/my-ajax-handler.js', array('jquery'), '0.1.0', true );
         wp_enqueue_script(array('my-ajax-handler'));
         $vars = array('ajaxurl' =&gt; admin_url('admin-ajax.php'));
         wp_localize_script('my-ajax-handler', 'my_ajax_handler_var', $vars); 
     }
  
      add_action( 'wp_ajax_rc_generate_pa', 'rc_generate_p' );
          function rc_generate_p(){
              $pass = (string)wp_generate_password(8, true, false); 
              echo $pass;
              header('Content-Type: application/json');
              $results = json_encode($pass);
              echo $results;
              exit;
          }    
  </code></pre>
  
  <p>I have seen similar problems on this site and tried the solution,but no success. I am new to WordPress plugin development.   </p>