title: AJAX POST - how to use a js variable in PHP
body: <p>The first time the page loads, there will not be anything in the POST data array. After it runs I want to be able to use whatever variable I send in the  POST data in the PHP code so I can query my database based on parameters sent. Do I need to reload the page somehow to do this?</p>
  
  <h3>PHP:</h3>
  
  <pre><code>if(isset($_POST['boarder'])){
      $boarder = $_POST['boarder'];
      function boarderCheck($boarder){
          echo "&lt;script type ='text/javascript'&gt;alert('$boarder');&lt;/script&gt;";
      }
      boarderCheck($boarder);
  } else {
  ?&gt;
    &lt;script defer src="http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script src="map.js"&gt;&lt;/script&gt;
  &lt;?
  };
  ?&gt;
  </code></pre>
  
  <h3>JavaScript (map.js)</h3>
  
  <pre><code>$.ajax({
    type: "POST",
    data: {boarder: 'test'},
    dataType: 'text',
    success: function(response) {
      console.log(response);
    }
  })
  </code></pre>