js 异步处理Json格式数据的典型应用

12年前

js 异步处理Json格式数据的典型应用

<script type="text/javascript">  xmlHttp=null;  function showHint(str){   if (str.length==0){     document.getElementById("txtHint").innerHTML="";    return;   }   try{// Firefox, Opera 8.0+, Safari, IE7    xmlHttp=new XMLHttpRequest();   }catch(e){// Old IE    try{     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");    }catch(e){     alert ("Your browser does not support XMLHTTP!");     return;      }   }   url="http://127.0.0.1:9997/api/p/internal/ucenter/login?loginName=test55&password=000000";   url=url+"&sid="+Math.random();   xmlHttp.open("GET",url,false);   xmlHttp.send(null);      //alert(eval(xmlHttp.responseText))   document.getElementById("txtHint").innerHTML=xmlHttp.responseText;  }  </script> 

全部

<html>  <head>  <script type="text/javascript">  xmlHttp=null;  function showHint(str){   if (str.length==0){     document.getElementById("txtHint").innerHTML="";    return;   }   try{// Firefox, Opera 8.0+, Safari, IE7    xmlHttp=new XMLHttpRequest();   }catch(e){// Old IE    try{     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");    }catch(e){     alert ("Your browser does not support XMLHTTP!");     return;      }   }   url="http://127.0.0.1:9997/api/p/internal/ucenter/login?loginName=test55&password=000000";   url=url+"&sid="+Math.random();   xmlHttp.open("GET",url,false);   xmlHttp.send(null);      //alert(eval(xmlHttp.responseText))   document.getElementById("txtHint").innerHTML=xmlHttp.responseText;  }  </script>   </head>  <body>  <form>   First Name:  <input type="text" id="txt1" onkeyup="showHint(this.value)">  </form><p>Suggestions: <span id="txtHint"></span></p>     </body>  </html>

js 异步处理Json格式数据的典型应用