執行個體講解用Javascript調用ASP實現過程 (轉載)

來源:互聯網
上載者:User

你或許見過這樣的調用方式:
<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規範,否則結果會提示指令碼錯誤或者一片空白!!

 

http://www.ninedns.com/tech-asp/20074221741154644.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.