title: load a php form in the same page using jquery and ajax
body: <p>I want a function that loads the values from a PHP form and show the result in a div in the same file ;</p>
  
  <p>I have a form in PHP file with the code bellow :</p>
  
  <pre><code>&lt;?php
  
   echo "&lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'&gt;&lt;/script&gt;";
  echo"&lt;script type='text/javascript' src='script.js'&gt;&lt;/script&gt;";
  
  
  echo"&lt;form method='post' action=''  &gt;";
  echo " &lt;select name='mat'&gt;&lt;option value=''&gt;Choose: &lt;/option&gt;";
  echo"&lt;option &gt;hello&lt;/option&gt;";
  echo"&lt;/select&gt;";
  echo"&lt;input type = 'submit'  value='next' onclick='submit();' /&gt;";
  echo"&lt;/form&gt;";
  
  echo"&lt;div id ='result'&gt; &lt;/div&gt;";
  ?&gt;
  </code></pre>
  
  <p>and the function in <code>script.js</code> is :</p>
  
  <pre><code>function submit() {
      $(function () {
          var mat = "mat";
          var dataString = 'mat=' + mat;
          $.ajax({
              type: "POST",
              url: "check.php",
              data: dataString,
              success: function (res) {
                  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;").hide().fadeIn(2500, function () {
                      $('#result').html(res + "&lt;br /&gt;&lt;br /&gt; Finished");
                  });
              }
          });
          return false;
      });
  }
  </code></pre>
  
  <p>and the <code>check.php</code> that load the values is :</p>
  
  <pre><code>&lt;?php 
  function safe($value)
  {
      htmlentities($value, ENT_QUOTES, 'utf-8');
      return $value;
  }
  if (isset($_POST['mat'])) {
      $mat = safe($_POST['mat']);
      echo ($mat);
  }
  elseif (!isset($_POST['mat'])) {
      header('Location: error?mat=notfound');
  } ?&gt;
  </code></pre>
  
  <p>But when I click next in the fist PHP file, it doesn't show anything, can you find the error?</p>