title: jQuery.ajax - Duplicate Content After Posting Data Back To The Same Page
body: <p><strong>Problem 1:</strong> My content overlaps itself twice after I post some data back to the same page using <code>jQuery.ajax()</code>. The reason why I'm posting data back to the same page is because I need to pass my JavaScript values to the PHP side.</p>
  
  <p><strong>Question:</strong> How do I edit my code such that there will only be 1 copy of my content, before and after posting of data to the same page?
  <hr />
  <strong>Problem 2:</strong> You may have noticed there is a <code>$("#test").html(data);</code> in my bingo function and a <code>&lt;span id="test"&gt;&lt;/span&gt;</code> in my body. I can't seem to remove them if not the passing of Javascript values to the PHP side would not work as shown by my <code>print_r()</code>.</p>
  
  <p><strong>Question:</strong> Is there any way I can remove them but still pass my values from JavaScript to PHP using <code>jQuery.ajax()</code>?
  <hr />
  <strong>bingo.php</strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
              &lt;script type="text/javascript" src="js/jquery-1.7.2.min.js"&gt;&lt;/script&gt;
              &lt;?php
              if (!isset($_POST['varA']) &amp;&amp; !isset($_POST['varB']))
              {
              ?&gt;
                  &lt;script type="text/javascript"&gt;
                  $(document).ready(bingo);
  
                  function bingo()
                  {
                      jQuery.ajax({
                          type: "POST",
                          data:  {varA: "123", varB: "456"},
                          success: function(data)
                          {
                              alert("POST to self is successful!");
                              $("#test").html(data);
                          }
                      });
                  }
                  &lt;/script&gt;
                  &lt;?php
              }
              else
              {
                  print_r($_POST['varA']);
                  echo " - ";
                  print_r($_POST['varB']);
              }
              ?&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;input type="text" value="meow"/&gt;
          &lt;span id="test"&gt;&lt;/span&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>