<html>
<head>
<title>RS MIND Page</title>
</head>
<script language=Javascript>
function DoSomething() {
var serverURL = "http://dino/rsmind/mind.asp";
var co = RSExecute( serverURL, "Method1" );
}
</script>
<body>
<script language=Javascript src="rs.htm"></script>
<script language=Javascript>RSEnableRemoteScripting();</script>
Remote Scripting for <i>MIND</i>.
<p>
<INPUT TYPE=button NAME="Button1" VALUE="Button1"
language=Javascript onclick="DoSomething();">
</p>
</body>
</html>
Figure 5 Call Object Properties
Name | Description |
ID | ID of the request. |
status | A value denoting the failure or the success of the operation. -1 for failure, 0 for success. |
message | A message describing what happened. |
data | Raw data returned by the server, if any. |
return_value | An object returned by the server, if any. Needs to be evaluated. |
context | A string identifying the context of the operation. It's one of the RSExecute's arguments. |
Figure 6 RSGetASPObject
function RSGetASPObject(url)
{
var cb, ecb, context;
var params = new Array;
var request = MSRS.startRequest(url,"GetServerProxy",
params,cb,ecb,context);
if (request.status == MSRS.S_COMPLETED)
{
var server = request.return_value;
server.location = url;
server.exec = MSRS.processRequest;
return server;
}
alert("Failed to create ASP object for : " + url);
return null;
}
Figure 7 Typical RS Server
<% RSDispatch(); %>
<SCRIPT RUNAT=SERVER language=Javascript>
<!--#INCLUDE FILE="http://dino/rsmind/rs.asp"-->
// Declaration of the Scriptlet's vtable.
function ServerSideScriptlet()
{
this.Method1 = DoMethod1;
this.Method2 = DoMethod2;
}
// vtable of the Scriptlet.
public_description = new ServerSideScriptlet();
// Implementation of Method1.
// Returns an object.
function DoMethod1()
{
return new Date;
}
// Implementation of Method2.
// Returns raw data.
function DoMethod2()
{
return "My name is Method2";
}
</SCRIPT>
Figure 9 SimulateRSDispatch
<HTML>
<script language=Javascript>
function SimulateRSDispatch()
{
// RSDispatch reads these through Request
var methodname = "Method1";
var param_count = 0;
// Initialize the dispatch table
dispatchVTbl = public_description;
if( typeof(dispatchVTbl[methodname]) == "function" )
{
var params = "";
var dispatch = "dispatchVTbl." + methodname + "(" + params + ")";
// execute the method through eval()
alert( "Ready for eval( '" + dispatch + "' )" );
var r = eval( dispatch );
// do something to test the return value
alert( r.getYear() );
}
return true;
}
// OBJECT IMPLEMENTATION
// This is a server-side scriptlet whose methods
// you call from the client page.
function Description()
{
this.Method1 = Method1;
this.Method2 = Method2;
}
public_description = new Description();
function Method1()
{
return new Date;
}
function Method2()
{
return new Array("blue","red","green","yellow","orange");
}
</script>
<BODY>
<script language=Javascript>
SimulateRSDispatch();
</script>
</BODY>
</HTML>
Figure 11 UnEval and Eval
<HTML>
<HEAD>
<TITLE>UnEval and Eval Sample</TITLE>
</HEAD>
<script language="JavaScript">
function Description() {
this.Method1 = DoMethod1;
this.Method2 = DoMethod2;
}
function DoMethod1() {
alert( "Method n. 1" );
}
function DoMethod2() {
alert( "Method n. 2" );
}
function TestUneval() {
public_description = new Description();
s = uneval( public_description );
alert( "public_description unevaluates to: \n\n" + s );
o = eval( s );
alert( "Executing Method1..." );
o.Method1();
alert( "Executing Method2..." );
o.Method2();
}
</script>
<BODY>
<script language="JavaScript" src="uneval.htm"></script>
Click to see an example of <b>uneval</b> and <b>eval</b>.<br>
By clicking you will execute the following code:<hr>
<code>
public_description = new Description();<br>
s = uneval( public_description );<br>
alert( "public_description unevaluates to: \n\n" + s );<br>
o = eval( s );<br>
alert( "Executing Method1..." );<br>
o.Method1();<br>
alert( "Executing Method2..." );<br>
o.Method2();<br>
</code>
<hr>
<INPUT type=button value="Test Uneval()" language=Javascript
onclick="TestUneval();">
</BODY>
</HTML>