title: How to pass javascript/jQuery variable to PHP using POST method
body: <p>This is really basic. All I want to do is measure the html width of a browser window, and pass that data to a PHP script so that I can adjust what information is passed to the site.</p>
  
  <p>I've got the HTML width part down. I'm just having trouble passing the Javascript/jQuery variable to the PHP script using AJAX.</p>
  
  <p>Here's the Javascript/jQuery. It is written in PHP so that I can use the <code>include()</code> function later.</p>
  
  <pre><code>echo 
  '&lt;script&gt; 
      htmlWidth = $("html").width();
      $.ajax({
          type: "POST",
          url: "mobileView.php",
          data:{ width: htmlWidth }
      }) 
  &lt;/script&gt;';
  </code></pre>
  
  <p>And here's the PHP:</p>
  
  <pre><code>$width = $_POST['width'];
  function mobileView(){
      if ($width &lt; 950){
          return true;
      } else{
          return false;
      }
  }
  mobileView();
  </code></pre>