title: ajax jquery php: w3school example jquery ajax post not displaying suggestion
body: <p>I tried the following code from w3schools. When I enter letters in a input txt box, suggestions should get displayed accordingly. However, nothing is getting displayed as suggestion. I'm not able to get the txt value with serialize.
  In gethint.php, since it is a post request, i changed the original  $q=$_GET["q"]; to $q=$_POST["q"].
  Can someone tell me on what i'm doing wrong? thank you.</p>
  
  <p>post_example.html</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function(){
    $("input").keyup(function(){
      // txt=$("input").val();
      txt=$("input").serialize();
      $.post("gethint.php",txt,function(result){
        $("span").html(result);
      });
    });
  });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;p&gt;Start typing a name in the input field below:&lt;/p&gt;
  First name:
  
  &lt;input type="text" &gt;
  &lt;p&gt;Suggestions: &lt;span&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>gethint.php</p>
  
  <pre><code>&lt;?php
   // Fill up array with names
   $a[]="Anna";
   $a[]="Brittany";
   $a[]="Cinderella";
   $a[]="Diana";
   $a[]="Eva";
   $a[]="Fiona";
   $a[]="Gunda";
   $a[]="Hege";
   $a[]="Inga";
   $a[]="Johanna";
   $a[]="Kitty";
   $a[]="Linda";
   $a[]="Nina";
   $a[]="Ophelia";
   $a[]="Petunia";
   $a[]="Amanda";
   $a[]="Raquel";
   $a[]="Cindy";
   $a[]="Doris";
   $a[]="Eve";
   $a[]="Evita";
   $a[]="Sunniva";
   $a[]="Tove";
   $a[]="Unni";
   $a[]="Violet";
   $a[]="Liza";
   $a[]="Elizabeth";
   $a[]="Ellen";
   $a[]="Wenche";
   $a[]="Vicky";
  
   //get the q parameter from URL
   $q=$_POST["q"];
  
   //lookup all hints from array if length of q&gt;0
   if (strlen($q) &gt; 0)
     {
     $hint="";
     for($i=0; $i&lt;count($a); $i++)
       {
       if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
         {
         if ($hint=="")
           {
           $hint=$a[$i];
           }
         else
           {
           $hint=$hint." , ".$a[$i];
           }
         }
       }
     }
  
   // Set output to "no suggestion" if no hint were found
   // or to the correct values
   if ($hint == "")
     {
     $response="no suggestion";
     }
   else
     {
     $response=$hint;
     }
  
   //output the response
   echo $response;
   ?&gt;
  </code></pre>