title: Submit form and show results on same page without refresh
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/13369940/how-to-have-user-submit-text-in-form-and-ajax-it-to-enter-to-db-and-show-up-on-s">How to have user submit text in form and AJAX it to enter to db and show up on same page?</a>  </p>
  </blockquote>
  
  
  
  <p>What I want to do:</p>
  
  <p><strong>index.html</strong> -> form submit to <strong>some.php</strong> -> process data (from index.html)  and send data to <strong>server.php</strong> -> returning results to a index.html div.</p>
  
  <p>I've read ajax, jQuery, I have seen hundreds of questions on this site, but I couldn't figure it out yet.</p>
  
  <p>index.html:</p>
  
  <pre><code>&lt;form action="some.php"  method="post"&gt;
      Start date: &lt;br/&gt; &lt;input name="idate" id="firstdate" type="text" /&gt;&lt;br /&gt;
      End date: &lt;br /&gt; &lt;input name="fdate" id="seconddate" type="text" /&gt;&lt;br /&gt;
      &lt;br /&gt;
      &lt;input type="button" id="searchForm" onclick="SubmitForm();" value="Send" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>some.php:</p>
  
  <pre><code>&lt;?php
  session_start();
  $_SESSION['data1'] = $_POST['firstdate'];
  $_SESSION['data2'] = $_POST['seconddate'];
  ?&gt;
  
   function drawChart() {
      var jsonData = $.ajax({
          url: "server.php",
          dataType: "json",
          async: false
      }).responseText;
  
      var obj = jQuery.parseJSON(jsonData);
      var data = google.visualization.arrayToDataTable(obj);
  
  (...)
  </code></pre>
  
  <p>server.php:</p>
  
  <pre><code>$SQLString = "SELECT    
              count(score) as counts,
              DATE(date),
              SUM(CASE WHEN gender = 1 then 1 ELSE 0 END) Male,
              SUM(CASE WHEN gender = 2 then 1 ELSE 0 END) Female,
              AVG(age) as age, score
              FROM persons  
              WHERE date &gt; '".$_SESSION['date1']."' AND date &lt; '".$_SESSION['date2']."' 
              GROUP BY DATE(date) 
              ORDER BY DATE(date) asc";   
  
  (...) 
  $data[0] = array('day','counts','Male','Female','Age','Score');     
  (...)
  echo json_encode($data);
  </code></pre>