Whats wrong in my Simple Ajax Code?
===

i try to write simple ajax code to send request and receive some data but it's doesn't work correctly!!!whats problem?

        <html>
        <head>
            <script type="text/javascript" language="javascript" >
            var pageurl="index.php?code=";
            var httpreq=gethttp();
           function answer(){
                if (httpreq.readyState==4){
                  var r=httpreq.responseText;
                  document.getElementById("ttext").value=r;
                }
            }
            function sendandrecive()
            {
                var code=document.getElementById("userinfo").value;
                  httpreq.open("GET",pageurl+code,true);
                  httpreq.onreadystatechange=answer;
                  httpreq.send(null);
            }
    
    function gethttp(){
                var xmlhttp;
                if (window.XMLHttpRequest){
                    xmlhttp=new XMLHttpRequest();
                   }else{
                       xmlhttp=new ActivXObject("Microsoft.XMLHTTP");
                   }
                   return xmlhttp;
            }
            </script>
        </head>
        <body>
           <input type="text" name="userinfo"/><br/>
           <input type="button" value="Submit" onclick="sendandrecive();" /><br/>
           <input type="text" name="ttext"  />
        </body>
    </html>
and this is my php page to procce request data.
    <?php
      $p=$_GET["code"];
       if ($p=="hexcoder"){
         echo "your name is HexCoder!";
       }
       else
       {
         echo "no, try again!";
       }
     ?>