title: How to display something from one page to another using jQuery?
body: <p>This is my code so far:</p>
  
  <p>The HTML:</p>
  
  <pre><code>&lt;form&gt;
      &lt;label&gt;First Name&lt;/label&gt; &lt;input type="text" class="first" /&gt;&lt;br /&gt;
      &lt;label&gt;Last Name&lt;/label&gt; &lt;input type="text" class="last" /&gt;&lt;br /&gt;
      &lt;label&gt;Age&lt;/label&gt; &lt;input type="text" class="age" /&gt;&lt;br /&gt;
      &lt;input type="button" class="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The PHP:</p>
  
  <pre><code>$first = mysql_real_escape_string($_POST['first']);
  $last = mysql_real_escape_string($last = $_POST['last']);
  $age = mysql_real_escape_string($_POST['age']);
  
  $query = mysql_query( "INSERT INTO people(first, last, age) VALUES ('$first', '$last', '$age')" );
  
  if ($query) {
      echo "Success: $first $last has been entered";
  } else {
      echo "FAIL!!!";
  }
  </code></pre>
  
  <p>The JQuery:</p>
  
  <pre><code>$('.submit').click(function() {
  
      var first = $('.first').val();
      var last = $('.last').val();
      var age = $('.age').val();
  
      var dataString = 'first=' + first + '&amp;last=' + last + '&amp;age=' + age;
  
      $.ajax({
          type: 'post',
          url: 'practise_process.php',
          data: dataString,
          success: function() {
              alert('success');
          }, error: function() {
              alert('error');
          }
      });
  
  });
  </code></pre>
  
  <p>Right now I can use the above code to enter form input into a database via the ajax function without refreshing the page. But how can I display something from the PHP script (practise_process.php) to the form page?</p>
  
  <p>this part:</p>
  
  <pre><code>if ($query) {
      echo "Success: $first $last has been entered";
  } else {
      echo "FAIL!!!";
  }
  </code></pre>
  
  <h2>EDIT</h2>
  
  <p>I made this change to my PHP file:</p>
  
  <pre><code>if ($query) {
      $message = "Success: $first $last has been entered";
  } else {
      $message = "FAIL!!!";
  }
  
  
  echo "
  
  &lt;script type='text/javascript'&gt;
  var foo = $message;
  &lt;/script&gt;
  
  ";
  </code></pre>
  
  <p>and changed the success of the ajax function on my form page to this:</p>
  
  <pre><code>    success: function() {
          alert(foo);
      }
  </code></pre>
  
  <p>But the var foo which was set on the PHP file isn't being recognized on the form file.</p>