This FAQ assumes that you have configured your server .ASP page to accept remote scripting calls. There is another FAQ dedicated to that concept in the VBScript area.
I am also going to assume that your pages are in a subdirectory underneath the web root.
For this FAQ we are going to assume the following directory structure:
/
/website
|-backend.asp --Remote scriptable ASP file
|-frontend.htm --Client side script
/_scriptlibrary
backend.asp
------------------------------------
Code:
<%RSDispatch%>
<!--#include file="../_scriptlibrary/rs.asp"-->
<script language="javascript" runat="SERVER">
var public_description = server_object;
function server_object()
{ this.TestFunction = testfunction;
}
function testfunction(text_to_bold)
{ return '<b>' + text_to_bold + '</b>';
}
</script>
Ok.. So we have a backend.asp file configured to accept
remote scripting calls.
The first thing we need to do on the
client side is to include the remote scripting java stub.
We do this with the line:
Code:
<script language=javascript src="../_scriptlibrary/rs.htm"></script>
This enables remote scripting on the client web page.
There are two methods by with ASP code can be called. You can call it by invoking an ASP object, or by calling the methods on the ASP page individually.
I generally prefer calling the methods individually and that is the method I am going to cover in this FAQ.
To execute a remote method, we use the
RSExecute() function.
RSExecute returns a
Call Object. The Call Object is the means by which we get the status and result of a remote scripting call.
Lets create a client htm file
frontend.htm
--------------------------
Code:
<SCRIPT language=Javascript src="../_scriptlibrary/rs.htm">
</SCRIPT>
<script Language=javascript>
function testSync()
{ text_to_bold = testtext.value;
co = RSExecute("backend.asp","TestFunction",text_to_bold);
alert(co.return_value);
}
</script>
<input type="text" name="testtext" id="testtext">
<button onClick="testSync();">Test Me</button>
When you click the Test Me button, you should get a popup that says <b>Text in the text box</b>
That should get you started. There are full examples in the remote scripting download that completely explain async calls and object calls.
Have fun.