title: Ajax form return variables to php
body: <p>I have another question:</p>
  
  <p>Ajax Forms are working well. Most of them need to do mysql stuff and only return values if the entry could be written or not. I used just echo statements. For example echo "1"; if the values could be written and echo "2"; if the values could not be written.</p>
  
  <p>Now I need to call back 3 variables. I know that I can write them in an array. My problem is just, that I can't return this variable into my visible site.</p>
  
  <p>This is my JavaScript Code:</p>
  
  <pre><code>//Show statistic
  $('.statistic_submit').click(function(){
      if ($('#month').val() == 'none' || $('#year').val() == 'none') {
          $("#dialog_empty").dialog( "open" );
          return false;
      }
  
      var form = $('#statistic_view');  
      var data = form.serialize(); 
  
      $.ajax({
          url: "include/scripts/user_statistic.php",
          type: "POST",
          data: data,
          success: function (reqCode) {
              if (reqCode == 1) {
                  //Show generated table
                  $('.done').fadeOut('slow'); 
                  $('.done').fadeIn('slow');
              }
              if (reqCode == 2) {
                  //No values found
                  $('.done').fadeOut('slow');
                  $("#dialog_error").dialog( "open" );
              }
          }
      });
      return false;
  });
  </code></pre>
  
  <p>This is my html code:</p>
  
  <pre><code>&lt;div&gt;
      &lt;form id="statistic_view" action="include/scripts/user_statistic.php" method="post"&gt;
          &lt;select name="month" id="month"&gt;
              &lt;option value="none" class="bold italic"&gt;Monat&lt;/option&gt;
              &lt;?php 
                  for($i=1; $i&lt;=12; $i++){
                      if($i == $month)
                          echo "&lt;option value=\"".$i."\" selected&gt;".$month_name[$i]."&lt;/option&gt;\n";
                      else
                          echo "&lt;option value=\"".$i."\"&gt;".$month_name[$i]."&lt;/option&gt;\n";
                  }
              ?&gt;
          &lt;/select&gt;
          &lt;select name="year" id="year"&gt;
              &lt;option value="none" class="bold italic"&gt;Jahr&lt;/option&gt;
              &lt;?php 
                  for($i=2012; $i&lt;=$year; $i++){
                      if($i == $year)
                           echo "&lt;option value=\"".$i."\" selected&gt;".$i."&lt;/option&gt;\n";
                      else
                          echo "&lt;option value=\"".$i."\"&gt;".$i."&lt;/option&gt;\n";
                  }
              ?&gt;
          &lt;/select&gt;
          &lt;br/&gt;&lt;br/&gt;
          &lt;div id="user_statistic"&gt;
              &lt;input type="submit" id="small" class="statistic_submit" value="Daten anzeigen"&gt;
          &lt;/div&gt;
      &lt;/form&gt; 
      &lt;br /&gt;
      &lt;div class="done"&gt;
          &lt;p class="bold center"&gt;&lt;?php echo "Besucher ".$month_name[$month]." ".$year; ?&gt;&lt;/p&gt;
          &lt;canvas id="cvs" width="680" height="250"&gt;[No canvas support]&lt;/canvas&gt;
          &lt;script&gt;
              chart = new RGraph.Line('cvs', &lt;?php print($data_string) ?&gt;);
              chart.Set('chart.tooltips', &lt;?php print($labels_tooltip) ?&gt;);
              chart.Set('chart.tooltips.effect', 'expand');
              chart.Set('chart.background.grid.autofit', true);
              chart.Set('chart.gutter.left', 35);
              chart.Set('chart.gutter.right', 5);
              chart.Set('chart.hmargin', 10);
              chart.Set('chart.tickmarks', 'circle');
              chart.Set('chart.labels', &lt;?php print($labels_string) ?&gt;);        
              chart.Draw();
          &lt;/script&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And this my user_statistic.php:</p>
  
  <pre><code>... (mysql stuff)
      /******************************/
      /** Create diagram
      /******************************/
      $labels = array();
      $data   = array();
  
      for ($j=1; $j&lt;=$days; $j++) {
          $labels[$j] =$j;
          $data[$j] = $day_value[$j];
      }
  
      // Aggregate all the data into one string
      $data_string = "[" . join(", ", $data) . "]";
      $labels_string = "['" . join("', '", $labels) . "']";
      $labels_tooltip =  "['" . join("', '", $data) . "']";
  
      //data written 
      echo "1";
  </code></pre>
  
  <p>So echo "1"; tells my script that everything is fine. But now I need $data_string, $labels_string and $labels_tooltip. So how can I return these values from user_statistic.php into my side?</p>