title: AJAX Wordpress ACF update with button click id
body: <blockquote>
    <p>I using ACF wordpress to update acf field for user to populate with button id click. 
    I am getting Error as admin-ajax.php with 400
    <strong>Error POST <a href="https://domainname/wp-admin/admin-ajax.php" rel="nofollow noreferrer">https://domainname/wp-admin/admin-ajax.php</a> 400 ()</strong></p>
    
    <p><strong>Wordpress code on template</strong></p>
  </blockquote>
  
  <pre><code>&lt;button class="get_project" id="1479" name="urbtnid" data-postid="147"&gt;Get project&lt;/button&gt;
  &lt;button class="get_userbtn" value="&lt;?php echo get_current_user_id() ?&gt;" id="get_userbtn" &gt;&lt;?php echo get_current_user_id() ?&gt;&lt;/button&gt;
  </code></pre>
  
  <p>**</p>
  
  <blockquote>
    <p><strong>JQUery AJAX Code</strong></p>
  </blockquote>
  
  <p>**</p>
  
  <pre><code>  jQuery(function($){
      $('.get_project').click(function() {
        var stdid = jQuery('#get_userbtn').attr('value');
        var stdbtnid = this.id;
         jQuery.ajax({
               url: my_ajax_object.ajax_url,
              type : 'post',
               data: dataString,
              success : function( response ) {
                   console.log(response);
              }
          });
      })
  
  });
  </code></pre>
  
  <p>**</p>
  
  <blockquote>
    <p><strong>Function.php code</strong></p>
  </blockquote>
  
  <p>**</p>
  
  <pre><code>function my_enqueue_ajax_save() {
  
      wp_register_script( 'ajax-script', get_template_directory_uri() . '/pradeep-js-css/my-ajax-id-save-script.js', array('jquery') , false, true );
       wp_enqueue_script( 'ajax-script' );
  
      wp_localize_script( 'ajax-script', 'my_ajax_object',
              array( 'ajax_url' =&gt; admin_url( 'admin-ajax.php' ) ) );
  
  }
  add_action( 'wp_enqueue_scripts', 'my_enqueue_ajax_save' );
  add_action( 'wp_ajax_my_action', 'my_action' );
  add_action( 'wp_ajax_nopriv_my_action', 'my_action' ); 
  
  function my_action(){
      $postid = $_POST['stdid1'];;
      $fieldname = 'last_question_viewed'; 
      $fieldvalue = $_POST['stdbtnid1'];          
      update_post_meta($postid, $fieldname, $fieldvalue);
      echo $postid;
      wp_die($fieldname = '', $fieldvalue = '', $postid = ''); 
  
  } 
  </code></pre>
  
  <blockquote>
    <p><strong>Updated jquery with action</strong></p>
  </blockquote>
  
  <pre><code>jQuery(function($){
  
        var stdid = jQuery('#get_userbtn').attr('value');
        var stdbtnid = this.id;
        var dataString = 'stdid1=' + stdid + '&amp;stdbtnid1=' + stdbtnid; 
        $('.get_project').click(function() {
         var data = {
        action: "my_action",
        stdid: stdid,
        stdbtnid1: stdbtnid
      };
         jQuery.ajax({
               url: my_ajax_object.ajax_url,
              type : 'post',
               data: data,
              success : function( response ) {
                   console.log(response);
              }
          });
      })
  
  });
  </code></pre>