title: jquery using ajax to send html tag inner and save in php
body: <p>NEW</p>
  
  <pre><code>function save(){
      $.ajax({
      url:"save-script.php",
      type:'POST',
      data: getPageHTML()
      });
  }
  </code></pre>
  
  <p>This is how I had set ip my function.</p>
  
  <p>AJAX seems to be removing characters and symbols. The + and &amp; are replaced by spaces. I have tried using the encodeURIComponent but it ends up removing everything.</p>
  
  <p>This is how I am using it</p>
  
  <pre><code>data: encodeURIComponent(getPageHTML())
  </code></pre>
  
  <p>Am I doing this right? </p>
  
  <p>OLD</p>
  
  <p>I am trying to print out everything inside my <code>&lt;html&gt;</code> tags and send them to a php file.</p>
  
  <p>Here I am getting everything inside both tags</p>
  
  <p>index.html</p>
  
  <pre><code>function getPageHTML() {
      $("input").each(function(){
      $(this).attr("value", $(this).val());
      });
      return "&lt;html&gt;" + $("html").html() + "&lt;/html&gt;";
  }
  </code></pre>
  
  <p>Works fine with a button to see what I am getting.</p>
  
  <p><code>&lt;button onclick="console.log(getPageHTML());"&gt;Print html&lt;/button&gt;</code></p>
  
  <p>I would now like to sent it to my <code>save-html.php</code> file that looks like this.</p>
  
  <pre><code>&lt;?php
      echo "Here is your post:";
      print "&lt;pre&gt;";
          print_r($_POST);
      print "&lt;/pre&gt;";
  ?&gt;
  </code></pre>
  
  <p>Here is what I am trying</p>
  
  <pre><code>function save(){
          var query = $('getPageHTML').serialize();
          var url = 'save-html.php';
          $.post(url, query, function (response) {
           alert (response);
          });
      }
  </code></pre>
  
  <p>and the button <code>&lt;input type="button" value="Send" onclick="save()"/&gt;</code></p>
  
  <p>any ideas on what I am doing wrong here? </p>