title: Returning post data
body: <pre><code>$.post("../js.php", {state: state},
                              function(data) {
                                  return data;
                          });
  </code></pre>
  
  <p>Here's my jquery code. Like you can see it sends a post request to js.php.</p>
  
  <p>Here's the code for js.php.</p>
  
  <pre><code>{...}
  $query = "SELECT * FROM table WHERE x='" . $y . "'";
  
  $result = $mysqli-&gt;query($query);
  
  $num_rows = $result-&gt;num_rows;
  
  echo $num_rows ? $num_rows : 0;
  </code></pre>
  
  <p>Now, when I alert the "data" back in the js file then it displays fine. But when trying to return it or assign it to a variable it does not work. The console tells me that the variable that has been assigned the value of data is undefined.</p>
  
  <p>Any thoughts?</p>
  
  <p>Updated code:</p>
  
  <pre><code>var data = null;
  
  $.post("../js.php", {state: state},
  function(response) {
  data = response;
  });
  
  console.log(data);
  </code></pre>
  
  <p>Still not working. :(</p>