你也可能见过:
<!-- #include file="xxx.asp" -->

但是下">

实例讲解用Javascript调用ASP实现过程

80酷酷网    80kuku.com

  javascript|过程你或许见过这样的调用方式:
<script language="javascript" src="xxx.js"></script>
你也可能见过:
<!-- #include file="xxx.asp" -->

但是下边的调用你就不一定见过了:
<script language="javascript" src="xxx.asp?borid=5&page_no=3"></script>

是的,请相信您的眼睛,是用script的方式调用asp文件,其实这种方法网上已经运用得相当普通了,如果你玩过动网,就肯定知道它提供贴子调用的功能,想想,代码是不是类似这样子的?

<script language="javascript" src="xxx.asp?borid=5&page_no=3"></script>能将xxx.asp?borid=5&page_no=3的结果显示于页面,它好于<!-- #include file="xxx.asp" -->的地方或许您已经看出来了,就在于可以传递参数,并显示出结果,下边举一个简单的例子:

index.htm:
<html>
<body>
<script language="javascript" src="dy.asp?num=1"></script>
</body>
</html>
dy.asp:
<%
Dim temp
Temp=request.querystring("num")
If Temp=1 then
Response.write "document.write('www.baidu.com');"
Elseif Temp=2 then
Response.write "document.write('www.163.com');"
Else
Response.write "document.write('www.sohu.com');"
End if
%>
要注意的是ASP文件的输出内容必须按照javascript规范来编写,如:
Response.write "document.write('www.baidu.com');"
你的ASP文件输出的内容将是:
document.write('www.baidu.com');
这样就符合javascript规范,否则结果会提示脚本错误或者一片空白!!

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: