AJAX ASP ʵÀý

AJAX ÓÃÓÚ´´½¨¸ü¾ß½»»¥ÐÔµÄÓ¦ÓóÌÐò¡£

AJAX ASP ʵÀý

ÏÂÃæµÄÀý×ÓÑÝʾ£ºµ±Óû§ÔÚÊäÈë×Ö¶ÎÖмüÈë×Ö·ûʱ£¬ÍøÒ³ÈçºÎÓë web ·þÎñÆ÷½øÐÐͨÐÅ£º

ʵÀý

ÇëÔÚÏÂÃæµÄÊäÈë×Ö¶ÎÖмüÈë×Öĸ A-Z£º

ÐÕÃû£º

ËÑË÷½¨Ò飺

Àý×Ó½âÊÍ

ÔÚÉÏÃæµÄÀý×ÓÖУ¬µ±Óû§ÔÚÊäÈë×Ö¶ÎÖмüÈë×Ö·ûʱ£¬»áÖ´ÐÐÃûΪ "showHint()" µÄº¯Êý¡£

´Ëº¯Êý±» onkeyup ʼþ´¥·¢¡£

ÏÂÃæÊÇ HTML ´úÂ룺

ʵÀý

<html>
<head>
<script>
function showHint(str) {
    if (str.length == 0) { 
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("txtHint").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET", "gethint.asp?q=" + str, true);
        xmlhttp.send();
    }
}
</script>
</head>
<body>

<p><b>ÇëÔÚÏÂÃæµÄÊäÈë×Ö¶ÎÖмüÈë×Öĸ A-Z£º</b></p>
<form> 
ÐÕÃû£º<input type="text" onkeyup="showHint(this.value)">
</form>
<p>ËÑË÷½¨Ò飺<span id="txtHint"></span></p>
</body>
</html>

Ç××ÔÊÔÒ»ÊÔ

´úÂë½âÊÍ£º

Ê×ÏÈ£¬¼ì²éÊäÈë×Ö¶ÎÊÇ·ñΪ¿Õ£¨str.length == 0£©£»Èç¹ûÊÇ£¬Çå¿Õ txtHint ռλ·ûµÄÄÚÈݲ¢Í˳öº¯Êý¡£

²»¹ý£¬Èç¹ûÊäÈë×ֶβ»Îª¿Õ£¬Ôò½øÐÐÈçÏ£º

  • ´´½¨ XMLHttpRequest ¶ÔÏó
  • ´´½¨µ±·þÎñÆ÷ÏìÓ¦¾ÍÐ÷ʱִÐеĺ¯Êý
  • ·¢ËÍÇëÇóµ½·þÎñÆ÷É쵀 ASP Îļþ£¨gethint.asp£©
  • Çë×¢ÒâÌí¼Óµ½ gethint.asp µÄ q ²ÎÊý
  • str ±äÁ¿±£´æÁËÊäÈë×ֶεÄÄÚÈÝ

ASP Îļþ - "gethint.asp"

Õâ¸ö ASP Îļþ¼ì²éÐÕÃûÊý×飬ȻºóÏòä¯ÀÀÆ÷·µ»Ø¶ÔÓ¦µÄÐÕÃû£º

<%
 response.expires=-1
 dim a(32)
 'ÓÃÐÕÃûÌî³äÊý×é
 a(1)="Ava"
 a(2)="Brielle"
 a(3)="Caroline"
 a(4)="Diana"
 a(5)="Elise"
 a(6)="Fiona"
 a(7)="Grace"
 a(8)="Hannah"
 a(9)="Ileana"
 a(10)="Jane"
 a(11)="Kathryn"
 a(12)="Laura"
 a(13)="Millie"
 a(14)="Nancy"
 a(15)="Opal"
 a(16)="Petty"
 a(17)="Queenie"
 a(18)="Rose"
 a(19)="Shirley"
 a(20)="Tiffany"
 a(21)="Ursula"
 a(22)="Victoria"
 a(23)="Wendy"
 a(24)="Xenia"
 a(25)="Yvette"
 a(26)="Zoe"
 a(27)="Angell"
 a(28)="Adele"
 a(29)="Beatty"
 a(30)="Carlton"
 a(31)="Elisabeth"
 a(32)="Violet"

 '´Ó URL »ñÈ¡ q ²ÎÊý
 q=ucase(request.querystring("q"))

 '²é¿´Êý×éÖÐËùÓÐ hint£¬q µÄ³¤¶ÈÊÇ·ñ´óÓÚ 0
 if len(q)>0 then
   hint=""
   for i=1 to 30
     if q=ucase(mid(a(i),1,len(q))) then
       if hint="" then
         hint=a(i)
       else
         hint=hint & " , " & a(i)
       end if
     end if
   next
 end if

 'Èç¹ûδÕÒµ½ hint£¬Êä³ö "no suggestion"£¬»òÊä³öÕýÈ·µÄÖµ
 if hint="" then
   response.write("no suggestion")
 else
   response.write(hint)
 end if
%>
VUE