温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

AJAX如何调用ASP文件进行通信

发布时间:2022-03-19 15:40:04 来源:亿速云 阅读:113 作者:iii 栏目:web开发

本篇内容介绍了“AJAX如何调用ASP文件进行通信”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

AJAX ASP 实例

当用户在输入字段中键入字符时,会执行名为 "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>

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

%>

“AJAX如何调用ASP文件进行通信”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI