Library tutorials & articles

Remote Scripting With JavaScript and ASP

Testing remote scripting

Now that we've got the installation out of the way, let's jump straight in and create a remote scripting example. The example we're about to create is rather trivial, but never the less it demonstrates the capabilities of remote scripting in both the client and server domains.

Our example will accept a string from the user using JavaScript's prompt() method. Remote scripting is then used to create a server object from a page we will create called rev.asp. Rev.asp will contain a function called reverse, which accepts a string and returns that string reversed, using the VBScript function strreverse. We call this function and then use JavaScript's alert() function to show the result passed back from the ASP script to the client.

Enabling remote scripting on the client side
In order for remote scripting to work properly, it must be "enabled" by both the client (our HTML page) and the server (an ASP page which we will create shortly). Create a new file called client_test.html and save it into the directory above where you installed the remote scripting files. For example, if you installed them to c:\inetpub\wwwroot\_ScirptLibrary then you would save client_test.html to c:\inetpub\wwwroot.

Our client needs to include the JavaScript functions defined in rs.htm, and we can do this by using a script block between the <head> and </head> tags, like this:

<script language="JavaScript" src="_ScriptLibrary/RS.HTM"></script>

As mentioned earlier, rs.htm contains a bunch of JavaScript functions. One of these functions is called RSEnableRemoteScripting, and it uses the JavaScript function document.write to dynamically add an <applet> tag to our HTML page. This applet points to the rsproxy.class file that should reside in the _ScriptLibrary folder.

RSEnableRemoteScripting accepts one optional parameter: the directory on the server where it can find rsproxy.class. If no parameter is specified, then it assume that rsproxy.class exists in the _ScriptLibrary directory. We call RSEnableRemoteScripting between a script block, like this:

<script language="JavaScript">
RSEnableRemoteScripting("/_ScriptLibrary");
</script>

Because RSEnableRemoteScripting adds an applet to our HTML page, it should be called just after the <body> tag. Note however that this applet isn't visible in the output and isn’t shown when you view the pages source in the browser either.

So here's what our client_test.html page looks like so far:

<html>
<head>
<title> Remote Scripting Example </title>
<script language="JavaScript" src="_ScriptLibrary/RS.HTM"></script>

</head>
<body>

<script language="JavaScript">
RSEnableRemoteScripting("/_ScriptLibrary");
</script>

</body>
</html>

Before continuing, copy-paste the code above and save it as client_test.html. Call it up in your browser using the http://localhost syntax, such as http://mypc/client_test.html. If you notice any JavaScript errors, then double check that you've got all of the required files in the _ScriptLibrary directory and that you're using the correct paths in client_test.html.

The next thing we want to do is actually implement remote scripting into our HTML page. Add the following code just before the </head> tag:

<script language="JavaScript">

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

alert(objResult.return_value);
}

</script>

Also add the following code just before the </body> tag:

<form name="frmTest">
<input type="button" onClick="reverseString()" value="Reverse String >>">
</form>

As you can see, we've added a button to our HTML page. When it is clicked, the JavaScript function reverseString() is called. ReverseString prompts the user to enter a string, creates a new remote scripting object (from the rev.asp page which we will look at shortly), and calls its revStr function.

The RSGetASPObject() JavaScript function comes from including rs.htm into our page and accepts the name of an ASP script. It returns an object that contains each of the functions defined in that ASP script.

Don't worry if you don't understand everything at the moment because it will become clearer as we move on. At this point, all you need to do is have your client_test.html page looking like this:

<html>
<head>
<title> Remote Scripting Example </title>
<script language="JavaScript" src="_ScriptLibrary/RS.HTM"></script>

<script language="JavaScript">

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

alert(objResult.return_value);
}

</script>
</head>
<body>

<script language="JavaScript">
RSEnableRemoteScripting("/_ScriptLibrary");
</script>

<form name="frmTest">
<input type="button" onClick="reverseString()" value="Reverse String >>">
</form>

</body>
</html>

Comments

  1. 31 Jan 2006 at 12:17
    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". Do u know why this is happening.

    kumar
  2. 04 Nov 2003 at 20:23
    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/thycotic/articles/view.aspx?id=4

    sample asp.net application using remote scripting
    http://www.thycotic.com/dotnet_remotescripting.html

    -brian

    Quote:
    [1]Posted by rv_2000 on 7 Oct 2003 06:01 AM[/1]
    I have read this article on Remote scripting with Asp.  I am wondering if any support is there with Asp.Net. If there what are the relevant links to practice remote scripting with asp.net. Tx
  3. 07 Oct 2003 at 06:01

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

  4. 27 Sep 2003 at 16:36
    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 for your reference. I will appreciate if you have any suggestions or comments,

    The "snake.htm" calls snake.asp file from the server.  The snake.asp and snake.htm are in the same folder on the server. I am running the client browser from the server machine.


    <HTML>
    <HEAD>
    <TITLE>Remote Scripting Test</TITLE>
    </HEAD>
    <BODY>
    <SCRIPT LANGUAGE="JavaScript" src="../_ScriptLibrary/RS.HTM"></SCRIPT>
    <SCRIPT LANGUAGE="JavaScript">
      RSEnableRemoteScripting("../_ScriptLibrary")
    </SCRIPT>
    <SCRIPT LANGUAGE="JavaScript" for="btnStraight" event="onclick">
       snake = RSGetASPObject("snake.asp")
       cycle = T1.value;
       co = snake.TravelStraight(cycle);
    </SCRIPT>

    <SCRIPT LANGUAGE="JavaScript" for="btnStop" event="onclick">
       snake = RSGetASPObject("snake.asp")
       co = snake.STOP();
    </SCRIPT>

    <form name ="snake_frm">
    <p>Enter the No of Cycles    <input type="text" name="T1" size="5" tabindex="1"></p>
     <p> </p>
     <p>                     
     <input type="button" value="STRAIGHT" name="btnStraight">      
     </p>

     <p>     <input type="button" value="Right" name="btnRight">   
     <input type="button" value="CENTER" name="btnCenter">    
     <input type="button" value="LEFT" name="btnLeft">       
     </p>
     <p>                           
     <input type="button" value="STOP" name="btnStop"></p>
     <p> </p>
     <p> </p>
     <p> </p>
     <p> </p>
     <p> </p>
     <p> </p>
     <p> </p>
    </form>
    <p> </p>
    <p> </p>

    </body>
    </html>

  5. 25 Jun 2003 at 17:14

    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 tutorial to work. Does anybody know how I can dynamically look up SQL Queries on the serverside and dynamically change my page on the server side?!


    The tutorial just hangs never finds any of the users and locks the browser.


    Thanks


    Shep

  6. 26 May 2003 at 05:04
    The code is working very fine and saved me from refreshing the page again and agian.
    It requires Microsoft VM to run and also though a very common thing which just slips of our mind - use "../folder/_scriptlibrary" in the client file .
    This may be one of the reasons that its giving an error "Object doesn't support this property or method"
  7. 03 May 2003 at 10:05

    Hi Anil,
    This looks like solution to my problem,
    Romote scripting which was working suddenly stopped working don't know the reason. probably the JVM got changed sometime back Thanks alot. I will try changing JVM....to remote scripting...
    thanks again
    Amit.

  8. 30 Apr 2003 at 12:45
    Hi All,

    I had been struggling with remote scripting and getting separate erros on two machines I tried. On 1 it was "Failed to create object: <name of page>.asp" and the other, it said "Object does not support method".  

    I spent 4-5 hours and then came back the next day and it struck me after talking to a friend that it might be because my PC uses Sun JVM. Mind you, I have installed Win XP Service Pack 1 and my PC is updated as of yesterday. I then downloaded Microsoft JVM from http://www.entsol.com/html/the_microsoft_jvm.html and installed it. And guess what!  it works now.

    For you guys who're struggling to get Remote Scripting to work, try this and see if it works for you!

    Anil
  9. 24 Mar 2003 at 11:39

    I got the same error i had to change the path from


    <script language="JavaScript">
     RSEnableRemoteScripting("/_ScriptLibrary");
    </script>


    to


    <script language="JavaScript">
     RSEnableRemoteScripting("_ScriptLibrary");
    </script>
    and it worked

  10. 13 Dec 2002 at 08:17

    The article is great but when I run this I get an error saying failed to create object "people.asp"


    I am running win2kserver sp3/visual idev 6 sp5


    Thanks
    Jack

  11. 28 Oct 2002 at 20:07

    Install SP1 for Win XP.


    Due to litigation matters, JVM was not included in the release of XP (with IE6), but is now finally available in SP1.


    regards,
    KH

  12. 24 Oct 2002 at 09:09

    hi there,


    hey did you able to run "remote scripting with javascript and asp" tutorial successfully ? if so, pl help me in that.


    Thanks,


    viral shah.

  13. 07 Oct 2002 at 10:39

    Hello


    I had similar errors to those that you mentioned, i noticed that they occured soon after i had installed the sun jvm, after much head scratching and even altering rs.htm it dawned on me that perhaps the new jvm might be the reason and that i might not have any problems if i used microsofts jvm instead, i dont know if this is for sure, but when i disabled the sun jvm i didn't have any more of the problems that i had, which happen to be very similar to you own

  14. 19 Sep 2002 at 11:39
    I have in  c:\inetpub\wwwroot\test\scriptlibray installed all the files for the remote scripting to work( rs.htm,rs.asp,rxproxy.class,etc).
    I have  in c:\inetpub\wwwroot\test\catalog\config\test.asp which uses the remote scripting by adding this
    lines to the code
    <body>
    ....
    ....
    <!-- Incluir para Remote Scripting -->
    <script language="JavaScript" src="../../ScriptLibrary/rs.htm"></script>
    <script language="JavaScript">RSEnableRemoteScripting("../../ScriptLibrary");</script>
    <!---->
    </body>
    And it stills gives me the same error:"Object doesn't support this property or method" with a line number not matching a line in the code.

    What can I do? I have tried to re-install the rs files and it sill didn't work, what else can I do?
  15. 05 Sep 2002 at 17:34

    amitmathur23, you have to install the "Remote Scripting 1.0b" for resolve it...

  16. 26 Aug 2002 at 03:22
    I'm getting an error stating
    "Object doesn't support this property or method".
    When i debeg it, it is found on rs.htm file and on the line where
    "this.rsapplet.startRequest(request.id,url_context,url,this.REQUEST_MODE_COMPLETE);" is mentioned.
    Please help.
  17. 27 Jun 2002 at 07:36

    I have tried to run the samples on your article on RS and none of them work. I get an error when RSGetASPObject is invoked.
    The problem is in this method  MSRSstartRequest. The msg say Object does not support property or method was not handled. Is there something that I'm missing. I using InterDev 6 on Win2k SP2. Pls Help

  18. 26 Jun 2002 at 04:28

    you can contact the author at mitchell@devarticles.com  (sorry ... that information should be present in his profile)

  19. 26 Jun 2002 at 03:04

    Hi,


    The article is very good. But I have got a small problem. Whom do i Contact for further queries.
    Can the author look into the quries or problems if the users like me has some problems.


    Please let us know.


    Regards,


    Sailendra.


    email:tirusail@yahoo.com

  20. 01 Jan 1999 at 00:00

    This thread is for discussions of Remote Scripting With JavaScript and ASP.

Leave a comment

Sign in or Join us (it's free).

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

Related podcasts

  • The Future of .NET Dotfuscator with Gabriel Torok

    Keith and Woody sat down with PreEmptive President Gabriel Torok to discuss the news that Microsoft is including PreEmptive's Dotfuscator Community Edition in Visual Studio 2010. The guys also discussed how Dotfuscator can be used to assist with Feature Monitoring, Usage Expiry, and Tamper ...

Events coming up

  • Dec 15

    Portland Java User Group

    Portland, United States

    This month's topic: TBD----------PJUG meetings start with eat+meet+greet time (pizza and beverages are provided), followed by the featured speaker, then some time for Q&A, discussion, and sometimes a drawing to give away swag. :)It is...

Want to stay in touch with what's going on? Follow us on twitter!