title: How do I pass JSON back to my AJAX Request from PHP?
body: <p>I've built a simple hangouts application that notifies me when someone launches a hangout from on my webpage - outside of Google plus.</p>
  
  <p>I'm at the stage where I've called my server side script that notifies me that a new user has initiated a hangout and I need to pass a message back to the hangout to display an updated prompt to the users. Something along the lines of - A support engineer has been alerted to this hangout and will be with you shortly.</p>
  
  <p>I've read in the hangout data, including who has joined from the hangouts api and passed this to my server side code no problems. But I'm not sure how I pass information back to my hangout app via its ajax request.</p>
  
  <p>Here's my ajax request using jQuery.</p>
  
  <pre><code>var hangoutUrl = gapi.hangout.getHangoutUrl();
  var personsInHangout = gapi.hangout.getParticipants();
  
  var callbackUrl = 'http://styxofdynamite.bitnamiapp.com/notify.php?';
  
  $.ajax({
      url: callbackUrl,
      dataType: 'text',
      data: {
          "personsInHangout" : personsInHangout,
          "hangoutUrl" : hangoutUrl,
          "topic" : params['gd'],
      }
  }).done( function(data, status, xhr){
      //call was made process result
      $('.msg').html(data.msg);
  }).fail( function(xhr, status, error){
      $('.msg').html("There was a problem contacting the server. (" + status + ")");
  });
  </code></pre>
  
  <p>At the moment I'm not returning anything so I'm happily hitting the <code>.fail()</code>ideally I need to return something from notify.php back to this hangout application.</p>
  
  <p>Sever side snippet:</p>
  
  <pre><code>$personsInHangout = $_GET['personsInHangout'];
  $hangoutUrl = $_GET['hangoutUrl'];
  $topic = $_GET['topic'];
  
  $emailMessage = 'Hey Support Team, ';
  
  for($i = 0, $size = count($personsInHangout); $i &lt; $size; ++$i) {
      $emailMessage .= $personsInHangout[$i]['person']['displayName'];
      $emailMessage .= ' is currently waiting in the support ';
      $emailMessage .= '&lt;a href="'.$hangoutUrl.'"&gt;hangout&lt;/a&gt;';
      $emailMessage .= ' to discuss ' . $topic;
  }
  
  print $emailMessage;
  
  $to      = 'support@team.com';
  $subject = 'New Hangout Request';
  $headers = 'From: hangout.monitor@team.com' . "\r\n" .
  'Reply-To: hangout.monitor@team.com' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();
  
  mail($to, $subject, $emailMessage, $headers);
  
  //return something to say that a support engineer has been notified.
  </code></pre>