title: using POST to send js variable to php from iframe
body: <p>I am trying to pass a variable from js to a <code>backoffice</code> page.
  So far I've tried using a form and submitting it from javascript (but that refreshes the page, which I don't want) </p>
  
  <ul>
  <li>I ditched the form and when for an iframe (so the page doesn't reload everytime the data is submitted). The function is run every few seconds (so the form should be submitting): </li>
  </ul>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;iframe style="visibility:hidden;display:none" action="location.php" method="post" name="location" id="location"&gt;
   &lt;script&gt;
     /*Some other stuff*/
      var posSend = document.getElementById("location");
      posSend.value = pos;
   posSend.form.submit();
    &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <ul>
  <li>However my php page does not display the value posted <strong>(im not quite sure how to actually get the $_POST variable):</strong> </li>
  </ul>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  $postion = $_POST['location'];
  echo $_POST['posSend'];
  echo "this is the";
  echo $position;
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <ul>
  <li>I also tried <code>$.post</code> as suggested here <a href="https://stackoverflow.com/questions/15452802/using-post-to-send-js-variables-to-php-script">Using <code>$.post</code> to send JS variables</a> but that didn't work either.</li>
  </ul>
  
  <p>How do I get the <code>$_POST</code> variable value? I cannot use <code>$_SESSION</code> - as the <code>backoffice</code> is a different session. What is the best method to do this?</p>
  
  <p><strong>EDIT</strong> I'd rather avoid ajax and jquery</p>