title: Wordpress admin-ajax.php 400 (Bad Request) error
body: <p>I am trying to call a php function with a button press.</p>
  <p>This is my code so far:</p>
  <pre><code>    echo(&quot;&lt;button onclick=\&quot;import_file()\&quot;&gt; Import &lt;/button&gt;&quot;);        
  </code></pre>
  <p>The Javascript upload.js file:</p>
  <pre><code>    function import_file () {
     
       jQuery.ajax({
          url: my_ajax_object.ajax_url, 
          data: {action: 'final_save'},
          type: &quot;POST&quot;, //request type
          success:function(result){
           alert(result);
         }
       });
   }
  </code></pre>
  <p>and the action in the primary php file:</p>
  <pre><code> function final_save(){
      check_admin_referer('import-upload');
      set_time_limit(0);
      $this-&gt;file = $file;
      $result = $this-&gt;save();
      if ( is_wp_error( $result ) ){
          echo $result-&gt;get_error_message();
      }else{
          echo &quot;Success&quot;;
      }
  
  }
  
  add_action('wp_ajax_final_save', 'final_save');
  add_action('wp_ajax_no_priv_final_save', 'final_save');
  </code></pre>
  <p>I also enqueued the scripts in the same file:</p>
  <pre><code>function enqueue_script(){
      $plugins_url = plugins_url();
      $base_url = get_option( 'https://www.virtualmin.archives.com' );
      $plugins_dir = str_replace( $base_url, ABSPATH, $plugins_url );
      $plugin = $plugins_dir.'/really-simple-csv-importer/upload.js';
      wp_enqueue_script('js-file', $plugin, array('jquery'), '', false);
      wp_localize_script( 'js-file', 'my_ajax_object', array( 'ajax_url' =&gt; admin_url( 'admin-ajax.php' ) ) );
  
      //Load jQuery
      wp_enqueue_script('jquery');
  
  }
  </code></pre>
  <p>and calling this function from dispatch:</p>
  <pre><code>    function dispatch() {
          $this-&gt;header();
          $this-&gt;enqueue_script();
  //more code
  }
  </code></pre>
  <p>Dispatch being called here:</p>
  <pre><code>    function really_simple_csv_importer() {
      load_plugin_textdomain( 'really-simple-csv-importer', false, dirname( plugin_basename(__FILE__) ) . '/languages' );
      
      $rs_csv_importer = new RS_CSV_Importer();
      register_importer('csv', __('CSV', 'really-simple-csv-importer'), __('Import posts, categories, tags, custom fields from simple csv file.', 'really-simple-csv-importer'), array ($rs_csv_importer, 'dispatch'));
  }
  add_action( 'plugins_loaded', 'really_simple_csv_importer' );
  </code></pre>
  <p>I am getting an admin-ajax.php 400 (Bad Request) error. Any idea what am I doing wrong? This is being coded in a plugin.</p>