当前位置:编程学习 > JAVA >>

Ajax 实现

print?<html> 
    <head> 
    <title>hello ajax</title> 
    <script> 
    var xmlRequest=null; 
    function hint(content) 
    { 
         
        if(window.XMLHttpRequest) 
        { 
            xmlRequest=new XMLHttpRequest();     
        } 
        else if(window.ActiveXObject) 
        { 
            xmlRequest=new ActiveXObject("Microsoft.XMLHTTP"); 
        } 
        var url="helloAjax.php?name="+content+"&q="+Math.random(); 
         
        xmlRequest.onreadystatechange=stateChanged ; 
        xmlRequest.open("GET",url,true); 
        xmlRequest.send(null);   
    } 
    function stateChanged()  
    { 
        if (xmlRequest.readyState==4 || xmlRequest.readyState=="complete") 
        {  
        document.getElementById("targetDiv").innerHTML=xmlRequest.responseText; 
        }  
    } 
    </script> 
    </head> 
 
    <body> 
         
        hello ajax:<input type="text" id="inputField" name="txt" onkeyup="hint(this.value)"> 
        <div id="targetDiv"></div> 
    </body> 
</html> 

<html>
 <head>
 <title>hello ajax</title>
 <script>
 var xmlRequest=null;
 function hint(content)
 {
  
  if(window.XMLHttpRequest)
  {
   xmlRequest=new XMLHttpRequest(); 
  }
  else if(window.ActiveXObject)
  {
   xmlRequest=new ActiveXObject("Microsoft.XMLHTTP");
  }
  var url="helloAjax.php?name="+content+"&q="+Math.random();
  
  xmlRequest.onreadystatechange=stateChanged ;
  xmlRequest.open("GET",url,true);
  xmlRequest.send(null); 
 }
 function stateChanged()
 {
  if (xmlRequest.readyState==4 || xmlRequest.readyState=="complete")
   {
   document.getElementById("targetDiv").innerHTML=xmlRequest.responseText;
   }
 }
 </script>
 </head>

 <body>
  
  hello ajax:<input type="text" id="inputField" name="txt" onkeyup="hint(this.value)">
  <div id="targetDiv"></div>
 </body>
</html>helloAjax.php


[php]
<?php 
    echo $_GET["name"]; 
?> 

<?php
 echo $_GET["name"];
?>

 \
 

补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,