简体   繁体   中英

Classic asp include

I am trying to separate some asp logic out into a separate page. For now, I am trying to call a simple function.

Here is the simple index page that I am using

<html>
<head>
<title>Calling a webservice from classic ASP</title>
</head>
<body>
<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
 %>
  <!--#include file="aspFunctions.asp"-->
  <%
  doStuff()
End If
%>
<FORM method=POST name="form1" ID="Form1">
ID:
<INPUT type="text" name="corpId" ID="id" value="050893">
<BR><BR>
<INPUT type="submit" value="GO" name="submit1" ID="Submit1" >
</form>
</body>
</html>

Here is aspfunctions.asp

sub doStuff()
    Response.Write("In Do Stuff")
end sub

When i hit the submit button on my form i get the below sub doStuff() Response.Write("In Do Stuff") end sub

Microsoft VBScript runtime error '800a000d'

Does anyone have any idea what i could be doing wrong?

Any help is greatly appreciated

Thanks Damien Type mismatch: 'doStuff'

/uat/damien/index.asp, line 15

您必须在<%%>标记内包含asp函数。

aspfunctions.asp should be inside tags so the asp is "executed", eg

aspfunctions.asp:
<%
    sub doStuff()
        Response.Write("In Do Stuff")
    end sub
%>

Otherwise the asp in aspfunctions.asp is just seen as plain-text, so as far as the server is concerned, doStuff has never been defined.

You're including the other file within an if statement. This does not mean that it's dynamically included, it's not. It will always be included.

To see this in action try this sample:

<%
If 1=0 Then
'We never get here
%>
    <!--#include file="aspFunctions.asp"-->
<%
    dostuff()
End If
dostuff()
%>

如果我没记错,那么没有返回值的呼叫就不需要括号(未经测试的解决方案):

doStuff

Make changes in two places:

  1. In aspfunctions.asp write "sub doStuff" instead of sub doStuff()
  2. Call the function as doStuff not doStuff()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM