Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog

Remote Scripting MS Sample

Microsoft created an obtuse, complex to read Remote Scripting sample that demonstrates all it's capabilities we will reproduce here in running form:

remotems.htm looks like this:

   filename=/learn/test/remotems.htm

<Test Script Below>


<HTML>
<HEAD>
<TITLE>SIMPLE CLIENT</TITLE>
</HEAD>

<BODY>
<script language="JavaScript" src="/learn/test/remote/rs.htm"></script>
<script language="JavaScript">RSEnableRemoteScripting("/learn/test/remote/");</script>

<h2>Simple Remote Scripting Example</h2>

<br>
The following buttons invoke remote scripting calls to an ASP server.
<br>
<form>
<br><br><input type=button name=btnRSExecute value="RSExecute Method1" onclick="handleRSExecute()" style="width:250;height:25">
<br><br><input type=button name=btnRSExecuteAsynch value="RSExecute Method1 (async)" onclick="handleRSExecuteAsync()" style="width:250;height:25">
<br><br><input type=button name=btnRSGetASPObject value="aspObject = RSGetASPObject" onclick="handleRSGetAspObject()" style="width:250;height:25">
<br><br><input type=button name=btnASPObject value="aspObject.Method2 (async)" onclick="handleAspObject()" style="width:250;height:25">
<br><br><input type=button name=btnInvalidCall value="RSExecute Invalid Method3" onclick="handleInvalidCall()" style="width:250;height:25">

<SCRIPT LANGUAGE="javascript">

    var serverURL = "remotems.asp";
    var aspObject;

    function myCallBack(co)
    {
        alert("CALLBACK\n\n" +
                "status = " + co.status + "\n\n" +
                "message = " + co.message + "\n\n" +
                "context = " + co.context + "\n\n" +
                "data = " + co.data + "\n\n" +
                "return_value = " + co.return_value);
    } 

    function errorCallBack(co)
    {
        alert("ERROR_CALLBACK\n\n" +
                "status = " + co.status + "\n\n" +
                "message = " + co.message + "\n\n" +
                "context = " + co.context + "\n\n" +
                "data = " + co.data);
    }

    function handleRSExecute()
    {
        var co = RSExecute(serverURL,"Method1");
        myCallBack(co);    
    }

    function handleRSExecuteAsync()
    {
        RSExecute(serverURL,"Method1",myCallBack,"RSExecute");
    }

    function handleRSGetAspObject()
    {
        aspObject = RSGetASPObject(serverURL);
        var msg = "aspObject public_description\n";
        for (name in aspObject)
            msg += "   " + name + "\n";
        alert(msg);
    }

    function handleAspObject()
    {
        aspObject.Method2(myCallBack,errorCallBack,"aspObject");
    }

    function handleInvalidCall()
    {
        var co = RSExecute(serverURL,"Method3",myCallBack,errorCallBack,"Invalid RSExecute");
    }

</SCRIPT>

</form>


</BODY>
</HTML>

remotems.asp looks like this:

   filename=/learn/test/remotems.asp

<Test Script Below>


<%@ LANGUAGE=VBSCRIPT %>
<% RSDispatch %>

<!--#INCLUDE VIRTUAL="/learn/test/remote/rs.asp"-->
<SCRIPT RUNAT=SERVER Language=javascript>
    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","purple","cyan","magenta");
    }

</SCRIPT>


Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site