title: WP Ajax 400 Bad request. Ajax in Class and Method
body: <p>I am new to <strong>OOP PHP</strong> so this is likely where I am going wrong. </p>
  
  <p>Here is my simple class. It is called when I load the page and the additional jQuery works fine for sending the ajax request. </p>
  
  <p>EDIT:
  I have a new tab which I have created in the woocommerce account page. (knp_product_submission_content). This spits out some basic HTML. 
  When the user clicks an icon on the page, the data from the form is submitted via ajax (just the value of the action input). This should then return the content from the callback. </p>
  
  <pre><code>/**************
  Add the core js file in the main plugin file. 
  *********************/
  function knp_vendor_scripts(){  
      wp_enqueue_script( 'core', plugin_dir_url(__FILE__).'js/core.js', array(), false, true );
      wp_localize_script('core', 'vendor_ajax_object', array('ajax_url' =&gt; admin_url('admin-ajax.php')));
  
  }
  add_action( 'wp_enqueue_scripts', 'knp_vendor_scripts' );
  
  /**
  * New class initiated in a woocommerce endpoint function
  **/
  function knp_product_submissions_content(){ 
  
    //Create the views object for fetching and displaying. 
    $views = new submission_views();         
    echo '&lt;div class="ajax-container-div"&gt;';
       //response content should go here      
    echo '&lt;/div&gt;';
  
  }
  add_action('woocommerce_account_product-submissions_endpoint', 'knp_product_submissions_content');
  
  /**
  * Get the data from the form
  * the user has just clicked on
  */
  jQuery(document).ready(function(){
  
      jQuery('.knpv_form_submit').on('click', function(){
  
      var formID = 
      jQuery(this).closest('form.knpv_ajax_form').attr('id');
  
      var data = jQuery('#'+formID).serialize();
  
      jQuery.post(vendor_ajax_object.ajax_url, data, function(response) {
  
          jQuery('.ajax-container-div').html(response);
  
      });
  
    });
  
  });
  
  class submission_views{
      /**
      * Setup ajax action and callbacks
      */
      public function __construct(){
          //Get the form for a new submission
          add_action('wp_ajax_knpv_add_new_submission', array($this, 'knpv_add_new_submission_callback'));
          add_action('wp_ajax_nopriv_knpv_add_new_submission', array($this, 'knpv_add_new_submission_callback'));
      }
  
      /**
      * Get the form html and send back 
      */ 
      public function knpv_add_new_submission_callback(){ 
          ob_start(); 
          ?&gt;
  
          &lt;section class="knp_vendor_submission_form"&gt;
              &lt;div class="container"&gt;
                  &lt;div class="row"&gt;
                      &lt;div class="col-md-12"&gt;
                          &lt;?php echo do_shortcode('[gravityform id=3'); ?&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/section&gt;
  
          &lt;?php 
          $content = ob_get_clean();
          return $content;
      }
  </code></pre>
  
  <p>I am using this really just to replace some content on the page. It is triggered on click and the response I get back is </p>
  
  <blockquote>
    <p>400 Bad Request</p>
  </blockquote>
  
  <p>Am I placing add_action in the right place? How do I know if it is even seeing the callback function?</p>
  
  <p>TIA</p>