title: PHP + jQuery + Ajax form submission - return results on the same page
body: <p>I would like to have the following:</p>
  
  <p>User submits a form by a click (<code>index.php</code>), the form input is processed by an external PHP file (<code>search.php</code>) and results are posted on the original page (<code>index.php</code>) in a div.</p>
  
  <p>I have already got together most of the code. It submits a form on a click and sends it to a PHP script.</p>
  
  <p>What I would need now is that the result from the PHP script are given back to the original page (<code>index.php</code>).</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>function submit() {
      $(function() {
          var id = "id";
          var dataString = 'id=' + id;
          $.ajax({
              type: "POST",
              url: "inc/search.php",
              data: dataString,
              success: function() {
                  goToByScroll("result");
                  $('#result').html("&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;
                                     div class='center'&gt;&lt;img src='img/loader.gif' /&gt;&lt;/div&gt;").hide().fadeIn(2500, function() {
                  $('#result').html("Finished");
                  });
              }
          });
          return false;
      });
  }
  </code></pre>
  
  <p>My PHP file (for testing) is:</p>
  
  <pre><code>&lt;?php function safe($value)
  {
      htmlentities($value, ENT_QUOTES, 'utf-8');
      return $value;
  }
  if (isset($_POST['id'])) {
      $id = safe($_POST['id']);
      echo ($id);
  }
  elseif (!isset($_POST['id'])) {
      header('Location: error?id=notfound');
  } ?&gt;
  </code></pre>
  
  <p>I would like to have results from <code>search.php</code> (in this case "id") posted into #result, but I can't figure out how :S</p>