title: Jquery Ajax passing data to another php file to update the database only allows to update once (Wordpress)
body: <p>I am trying to redirect the data using POST method to a file in Wordpress called functions.php. It is able to send the data detected from the textbox to that file and gets the return value by using wp_send_json($_POST). After getting the returned value, the value of the paragraph was able to change to its new value. But it only allows me to update it once unless the page is being refreshed or reloaded. What have i done wrong or have i missed? Below are my codes for this process.</p>
  
  <p><strong>functions.php</strong></p>
  
  <pre><code>function test_load(){
      if(isset($_POST) &amp;&amp; $_POST['element'] == 'header')
      {
          $name = $_POST['name'];
          $hidden = $_POST['hidden'];
  
          if( $hidden == 'tagline')
          {
              update_option( 'wpbst_tagline', $name );
          }
          else if( $hidden == 'footer')
          {
              update_option( 'wpbst_footer', $name );
          }
  
          wp_send_json($_POST);
      }
  }
  
  add_action('init', 'test_load');
  </code></pre>
  
  <p><strong>script</strong></p>
  
  <pre><code>&lt;script&gt;
  
    $(document).ready(function(){
  
      function custom_update_box( id ) {
  
          $(id).click(function () {
  
            if(id == '#tagline')
            {
              var dynamicDialog = $('&lt;div&gt;\ &lt;label&gt;\ Tagline :\ &lt;/label&gt;\  &lt;input type="hidden" value="tagline" id="hidden"&gt;\ &lt;input  id="update" class="form-control" type="textbox" value=\'' + $(this).html().trim() + '\'/&gt;\ &lt;/div&gt;');
              title = "Update Tagline";
            }
            else if(id == '#logo')
            {
              var dynamicDialog = $('&lt;div&gt;\ &lt;label&gt;\ Logo :\ &lt;/label&gt;\  &lt;input type="hidden" value="logo" id="hidden"&gt;\ &lt;input id="update" class="form-control" type="textbox" value=\'' + $(this).html().trim() + '\'/&gt;\ &lt;/div&gt;');
              title = "Update Logo";
            }
            else if(id == '#footer')
            {
              var dynamicDialog = $('&lt;div&gt;\ &lt;label&gt;\ Logo :\ &lt;/label&gt;\  &lt;input type="hidden" value="footer" id="hidden"&gt;\ &lt;input id="update" class="form-control" type="textbox" value=\'' + $(this).html().trim() + '\'/&gt;\ &lt;/div&gt;');
              title = "Update Footer";
            }
  
            dynamicDialog.dialog(
            { 
              title: title, 
              modal: true, 
              buttons: {
                  'Submit': function(e) {
                    console.log(e);
                    $.ajax({
                      type: "POST",
                      data: { name: $("#update").val() , hidden: $("#hidden").val() , element: "header"}
                    }) 
                    .done(function(msg) {
  
                      console.log($("#update").val());
  
                      if(id == '#tagline')
                        $(id).html(msg.name);
                      else if(id == '#logo')
                        $(id).html(msg.name);
                      else if(id == '#footer')
                        $(id).html(msg.name);
                    });
                    $(this).dialog('close');
                },
                  'Cancel': function() {
                  $(this).dialog('close');
                }
              }
  
            });
  
        });
  
      }
  
      custom_update_box("#tagline");
      custom_update_box("#logo");
      custom_update_box("#footer");
  
    });
  
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>    &lt;center&gt;
        &lt;span id="logo" class="bs-docs-booticon bs-docs-booticon-lg bs-docs-booticon-outline"&gt;
          &lt;?php echo $logo_decode-&gt;wpbst_logo_initial; ?&gt;
        &lt;/span&gt;
  
          &lt;td&gt;
            &lt;p id="tagline" name="blogdescription" class="lead"&gt;&lt;?php echo $result_tagline;?&gt;&lt;/p&gt;
            &lt;input id="tagline" type="hidden" name='blogdescription' value=&lt;?php echo '"'.$result_tagline.'"';?&gt; /&gt;
          &lt;/td&gt;
  
        &lt;p class="lead"&gt;
          &lt;a id="button" class="btn btn-outline-inverse btn-lg" href=""&gt;&lt;?php echo $button_decode-&gt;wpbst_button_name;?&gt;&lt;/a&gt;
        &lt;/p&gt;
      &lt;/center&gt;
  </code></pre>