php ajax


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!--          php,xmlHttp JS                  : -->
<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script>
        function getXmlHttpObject()
        {
            var xmlHttp=null;
            //        
            try{
                // Firefox, Opera 8.0+, Safari
                xmlHttp = new XMLHttpRequest();
            }catch(e){
                //Internet Explorer
                try{
                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                }catch(e){
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
            }
            return xmlHttp;
        }
        function clickbutton()
        {
            //  ID    input    
            var str = document.getElementById('txt').value;
            //location.href = "php.php?txt="+test.value;
            //    XmlHttp  
            xmlHttp = getXmlHttpObject();
            var url="php.php";
            var poststr="q="+str;
            //poststr=poststr+"&sid="+Math.random();
            // xmlHttp  onreadystatechange          
            xmlHttp.onreadystatechange=stateChanged;
            xmlHttp.open("POST",url,true);
            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xmlHttp.send(poststr);
            
        }
        function stateChanged()
        {
            if(xmlHttp.readyState==4)
            {
                var res = xmlHttp.responseText;
                alert(res);
                //document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
            }
        }   
    </script>
  </head>
  <body>
    <input type="text" name="txt" id="txt" />
    <a href="">test</a>
    <p onclick="clickbutton()" style="cursor:">jlfds</p>
    <input type="button" name="txt" id="button" value="button" onclick="clickbutton()" />
  </body>
</html>