title: How to send info to a PHP script with AJAX?
body: <p>I cannot get my simple ajax script to run. The code should be pretty simple.
  The ajax script is:</p>
  
  <pre><code>&lt;html&gt;
  
  &lt;head&gt;&lt;title&gt;Testing ajax&lt;/title&gt;
  
      &lt;script type="text/javascript"&gt;
  
          function ajax() {
  
              var xmlhttp;
  
              var fname=document.getElementById("fname").value;
  
              if(window.XMLHttpRequest) {
                  xmlhttp=new XMLHttpRequest();
              } else {
                  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
  
              xmlhttp.onreadystatechange=function() {
  
                  if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) {
  
                      document.getElementById("output").innerHTML=xmlhttp.responseText;
  
                  }
  
              }
  
              xmlhttp.open("GET","ajax.php?fname="+fname,true);
              xmlhttp.send();
  
          }
  
      &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  
      &lt;form&gt;
  
          &lt;input type="text" id="fname"&gt;
  
          &lt;input type="text" id="lname"&gt;
  
          &lt;input type="submit" id="submit" onclick="ajax()"&gt;
  
  
      &lt;/form&gt;
  
  
      &lt;div id="output"&gt;&lt;/div&gt;
  
  
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>And the php script is:</p>
  
  <pre><code>&lt;?php
  
  $fname=$_GET['fname'];
  
  echo "&lt;p&gt;Hello ".$fname."&lt;/p&gt;";
  
  ?&gt;
  </code></pre>
  
  <p>I have also tried:</p>
  
  <pre><code>xmlhttp.open("POST","ajax.php",true);
  xmlhttp.setRequestHeader("Content-type","application/pass-data");
  xmlhttp.send("fname="+fname);
  </code></pre>
  
  <p>I can't get neither post not get method to send data. Am I not seeing something simple?</p>