XML-txtHint-XMLHttpRequest Example

来源:互联网 发布:js数组对象常用方法 编辑:程序博客网 时间:2024/06/07 09:07

source: http://www.w3schools.com/xml/xml_http.asp


<script type="text/javascript">
function showHint(str)
{
if (str.length==0)
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlHttp=new XMLHttpRequest();
  }
else // for older IE 5/6
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
var url="gethint.asp?q=" + str;
url=url+"&amp;sid="+Math.random();
xmlHttp.open("GET",url,false);
xmlHttp.send();
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
</script>

 

<hr />
<h2>XMLHttpRequest Example</h2>
<p>When you type a character in the input field below, an XMLHttpRequest is sent to the server
- and
name suggestions are returned (from a file on the server):</p>
<table width="100%" style="border:1px solid #d4d4d4;background-color:#e5eecc;background-image:url('/images/bgfadegreen.gif');background-repeat:repeat-x" id="table18">
<tr><td align="center">
<p class="intro">Type a letter in the input box:</p>
<p class="intro">First Name</p>
<input type="text" id="txt1" onkeyup="showHint(this.value)" />
<br />
<p class="intro">Suggestions:</p>
<p class="intro"><span id="txtHint"></span></p>

</td></tr></table>
<br />
<hr />

 

原创粉丝点击