title: xmlhttp.send() and PHP $_POST[]
body: <p>I'm trying to make my first ajax form but I can't make it work. It is supposed to send some values to a .php file using POST method, make some calculations and retrieve the results. For some reason, I can't find the way to get the values in the php code. When I use print_r ($_POST) I can see all the values inserted in the form but if I try to get them using $_POST['input_name'] an  "Undefined index" error message is shown :S I don't know what I am doing wrong so any help would be appreciated.
  Here is the code I'm using:</p>
  
  <p>JQuery/Ajax:</p>
  
  <pre><code>$().ready(function() {
              $("#formulario").validate();
  });
  
   function calcularR(){
              if ($('#formulario').valid() ) 
                {
              if (window.XMLHttpRequest)
                {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
                }
              else
                {// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
              xmlhttp.onreadystatechange=function()
                {
                if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
                  {
                  document.getElementById("calculo").innerHTML=xmlhttp.responseText;
                  }
                }
              xmlhttp.open("POST","calcularT.php",true);
              xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  
              var form = document.getElementById('formulario');
              var formData = new FormData(form);
              xmlhttp.send(formData);
              }
          }
  </code></pre>
  
  <p>HTML: </p>
  
  <pre><code>&lt;form id="formulario" name="formulario" method="post" action="enviarR.php" enctype="application_x-www-form-urlencoded"&gt;
      &lt;div id="bulto1" class= "bult1"&gt;    
           &lt;label class="form-label-top" id="label_alto" &gt;Alto (cm)&lt;/label&gt;
          &lt;input type="text" class="required" id="alto1" name="alto1" size="21" maxlength="6" value = "" /&gt;
  
          &lt;label class="form-label-top" id="label_largo" for="input_26"&gt;Largo (cm)&lt;/label&gt;
          &lt;input type="text" class="required" id="largo1" name="largo1" size="21" maxlength="6" value = "" /&gt;
  
          &lt;label class="form-label-top" id="label_ancho" for="input_27"&gt;Ancho (cm)&lt;/label&gt;
          &lt;input type="text" class="required" id="ancho1" name="ancho1" size="21" maxlength="6" value = "" /&gt;
  
      &lt;/div&gt;
     &lt;input type="button" name="calcular" id="calcular" value="Calcular" onclick="calcularR()"&gt;
     &lt;input type="submit" name="enviar" id="enviar" value="Entrar"&gt;                           
  &lt;/form&gt;     
  &lt;div id="calculo" name="calculo"&gt;&lt;b&gt; &lt;/b&gt;&lt;/div&gt;
  </code></pre>
  
  <p>PHP (calcularT.php)</p>
  
  <pre><code>if(isset($_POST['largo1']) &amp;&amp; !empty($_POST['largo1'])){
      $largo = $_POST['largo1'];
      if(isset($_POST['ancho1']) &amp;&amp; !empty($_POST['ancho1'])){
          $ancho = $_POST['ancho1'];
          if(isset($_POST['alto1']) &amp;&amp; !empty($_POST['alto1'])){
              $alto = $_POST['alto1'];
              $t = calcularP($largo, $ancho, $alto);
              echo "Resultado: ".$t."&lt;br/&gt;";
           }else{
             echo "alto required &lt;br/&gt;";
           }
      }else{
        echo "ancho required&lt;br/&gt;";
      }
  }else{
      echo "largo required&lt;br/&gt;";
  }
  </code></pre>
  
  <p>This is just part of the code. First I try sending form data using </p>
  
  <pre><code>var alto = document.getElementById("alto").value;
  var ancho = document.getElementById("ancho").value;
  xmlhttp.send("alto="+alto+"&amp;ancho="+ancho);
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>var formData = new FormData(form);
  xmlhttp.send(formData);
  </code></pre>
  
  <p>and it worked just fine but the form has more inputs and some of them are not always sent, so I thought it was better to use formData instead but, as I said, I can't find the way to get the values in the php code. 
  Thanks in advance and please forgive my basic/bad english (this is not my native language. I'm learning that too :P)</p>