title: Getting multiple values returned from a $.ajax POST
body: <p>I have some ajax code that executes on mouseclick. It calls a file called update.php that does a bunch of stuff, including checking for user permissions, numerous database calls, etc.  In the end, I also want to be able to return a few variables from PHP for the callback to use, but not sure how to reference them - or if there's a better way to return this info.</p>
  
  <pre><code>$.ajax({
  type: "POST",
  url: "update.php",
  data: dataString,
  success: callback 
  
  });
  
  function callback(data, status)
  {
  // $("div").text(data);
  $("div.numbert").text("[first variable here]");
  $("div.numbert2").text("[second variable here]");
          }
  </code></pre>
  
  <p>From my update.php file (some snippets):</p>
  
  <pre><code>    if ($check_access &gt; 0)
      {
  // Update database 
  
  $sql = "UPDATE db SET access = '1' WHERE user = '$user'";
  $result = mysql_query($sql) or die(mysql_error());
  
  
  // Give access - function returns data to variable
  $value = GiveAccess($user);
  
  
  // Email - function returns data to variable
  $emaillist = emailAdmins($user);    
  
      } else {
  
  $message = "Sorry you do not have access";
      }
  </code></pre>
  
  <p>So I'd like to figure out how to use the variables $message, $value and $emaillist in my callback if possible.</p>
  
  <p>I'm wondering if I just need to make multiple $.ajax POST calls, with each .php function that returns a variable having it's own call?</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <h2>----UPDATE-------</h2>
  
  <p>Updated code trying to use the json methods - thanks for all the help - but seems I'm missing one last thing.</p>
  
  <pre><code>    $.ajax({
  type: "POST",
  url: "update.php",
  data: dataString,
  dataType: 'json',
      success: callback 
  
  });
  
  function callback(data, status)
  {
  // $("div").text(data);
  $("div.numbert").text(data.value);
  $("div.numbert2").text(data.emaillist);
  </code></pre>
  
  <p>and update.php:</p>
  
  <pre><code>    $storage = array();
  // Update database 
  
  $sql = "UPDATE db SET access = '1' WHERE user = '$user'";
  $result = mysql_query($sql) or die(mysql_error());
  
  
  // Give access - function returns data to variable
  $storage['value'] = "some user";
  
  
  // Email - function returns data to variable
      $storage['emaillist'] = "some stuff";   
  
      header('Content-type: application/json');
      echo json_encode($storage);
      exit(0);    
  </code></pre>
  
  <p>Thanks again.</p>