Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 52,071 times

Contents

Downloads

Related Categories

Remote Scripting With JavaScript and ASP - Enabling remote scripting on the server side

devarticles

Enabling remote scripting on the server side

Our client_test.html page includes JavaScript that is executed when a button is clicked on. This JavaScript contains a call to RSGetASPObject, which takes rev.asp as its first parameter.

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:


<!--#INCLUDE FILE="_ScriptLibrary/RS.ASP"-->
<% RSDispatch %>

Next we create a block of server side JavaScript code, like this:

<script language="JavaScript" runat="server">

var public_description = new MainMethod();

function MainMethod()
{
this.revStr = Function('strString','return reverse(strString)');
}

</script>

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">

function reverse(strString)
reverse = strReverse(strString)
end function

</script>

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:

this.revStr = Function('strString','return reverse(strString)');

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:

function reverseString()
{
var strTest = prompt("Enter String To Reverse:");
var objRS = RSGetASPObject("rev.asp");
var objResult = objRS.revStr(strTest);

alert(objResult.return_value);
}

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.

A call to any method of an object created from a call to RSGetASPObject returns an object itself. This object exposes several functions and variables, most notably return_value, which is the value returned from the call to the specific function (which in our case is revStr). In our client_test.html page, we use JavaScript's alert function to display the returned value in a message box.

Here's the entire code for rev.asp:

<!--#INCLUDE FILE="_ScriptLibrary/RS.ASP"-->
<% RSDispatch %>

<script language="JavaScript" runat="server">

var public_description = new MainMethod();

function MainMethod()
{
this.revStr = Function('strString','return reverse(strString)');
}

</script>

<script language="VBScript" runat="server">

function reverse(strString)
reverse = strReverse(strString)
end function

</script>

Hopefully you've now got our first sample up and running. Let's build on what we've learnt so far and add some database functionality to the mix.

Visit http://www.devarticles.com for more articles and free programming eBooks, or visit Socket6.com for your dose of daily developer news!

© devArticles.com 2001

Comments

  • Remote Scripting

    Posted by kumar_siva on 31 Jan 2006

    hi,
    i tried this it working in my local server (windows 2000). But when i uploaded these files on the internet server it showing an error message "OBJECT DOES NOT SUPPORT THIS PROPERTY OR METHOD"...

  • applet-free remote scripting for asp.net

    Posted by jimmyjam on 04 Nov 2003

    there are several applet-free alternatives to microsoft's implementation of remote scripting that will work with ASP.NET

    cross browser remote scripting client
    http://authors.aspalliance.com/thycot...

  • Remote scripting.

    Posted by rv_2000 on 07 Oct 2003

    I have read this article on Remote scripting with Asp. I am wondering :rolleyes: if any support is there with Asp.Net. If there what are the relevant links to practice remote scripting with asp.net. ...

  • Tried Installing JVM but still doesnt work

    Posted by Nikhil on 27 Sep 2003

    hi,
    I am trying some remote scripts. I am getting the same error "Failed to create the ASP object: url". I tried installing the JVM, but still i am receiving the error. I am pasting my code here f...

  • SQL Remote Scripting

    Posted by shep on 25 Jun 2003

    All I want to beable to do is have the Remote scripting return a matrix of the querry I submitted. I tried going through the tutorial on remote scripting step by step and can't get the List People SQL...