Create a new file called rev.asp and add the code shown below to rev.asp as we go. In order for rev.asp to participate in remote scripting, it must include the server version of rs.htm, which is rs.asp. Rs.asp includes a method called RSDispatch, which must be called immediately after rs.asp is included to initialise remote scripting:
<% RSDispatch %>
The code above creates a new object called public_description, which is an instance of a function called MainMethod. MainMethod is a constructor that contains a list of functions and how they should be mapped so that remote scripting can be used to call them. Note that the MainMethod function can be called anything you like.
Before we continue, add the following block of VBScript at the end of rev.asp:
<script language="VBScript" runat="server">
reverse = strReverse(strString)
If you now take a look at the code inside of MainMethod, then you will see that it creates a new method called revStr, which maps to our VBScript reverse function:
Whenever a client calls the revStr method, remote scripting will automatically call our VBScript function reverse. The Function() method is used to define the revStr method. Its first argument is the parameter(s) that the function we're mapping to accepts. Our VBScript reverse function accepts one parameter, and we specify it using 'strString'. Next we have the function signature, which specifies the return keyword as well as the function name we're mapping and its parameters.
Jumping back to our client_test.html, we have this code:
var strTest = prompt("Enter String To Reverse:");
var objRS = RSGetASPObject("rev.asp");
var objResult = objRS.revStr(strTest);
As you can see, it uses RSGetASPObject to create a new object containing all of the functions that we've defined in rev.asp. Because we've mapped our VBScript function reverse as revStr, we call objRS.revStr with one parameter, which is the string that it should reverse and return.