用Javascript调用ASP实现过程
你或许见过这样的调用方式:
<scriptlanguage="javascript"src="xxx.js"></script>
你也可能见过:
<!--#includefile="xxx.asp"-->
但是下边的调用你就不一定见过了:
<scriptlanguage="javascript"src="xxx.asp?borid=5&page_no=3"></script>
是的,请相信您的眼睛,是用script的方式调用asp文件,其实这种方法网上已经运用得相当普通了,如果你玩过动网,就肯定知道它提供贴子调用的功能,想想,代码是不是类似这样子的?
<scriptlanguage="javascript"src="xxx.asp?borid=5&page_no=3"></script>能将xxx.asp?borid=5&page_no=3的结果显示于页面,它好于<!--#includefile="xxx.asp"-->的地方或许您已经看出来了,就在于可以传递参数,并显示出结果,下边举一个简单的例子:
index.htm:
<html>
<body>
<scriptlanguage="javascript"src="dy.asp?num=1"></script>
</body>
</html>
dy.asp:
<%
Dimtemp
Temp=request.querystring("num")
IfTemp=1then
Response.write"document.write('www.baidu.com');"
ElseifTemp=2then
Response.write"document.write('www.163.com');"
Else
Response.write"document.write('www.sohu.com');"
Endif
%>
要注意的是ASP文件的输出内容必须按照javascript规范来编写,如:
Response.write"document.write('www.baidu.com');"
你的ASP文件输出的内容将是:
document.write('www.baidu.com');
这样就符合javascript规范,否则结果会提示脚本错误或者一片空白!!