Link to home
Start Free TrialLog in
Avatar of farzinm
farzinm

asked on

Remote Scripting

I came across this article and tried it but it doesnt seem to work for me.
http://msdn.microsoft.com/library/en-us/dnserv/html/server042699.asp?fname=true
Any help will be appreciated.
Thanks
Avatar of DaDMan
DaDMan
Flag of Canada image

Haaa... this good remote scripting... :-)
What problem do you encounter first of all?

Are you using Netscape or IE?
Do you have Norton on your pc? If so, does the script blocking is set to OFF? It must be.

Describe the problems you have.

Cheers
Avatar of farzinm
farzinm

ASKER

I will the first thing tommorrow morning ..dont have access to my files right now thanks!
Avatar of farzinm

ASKER

I am using IE but tried by code on Netscape too doesnt work on either browser
I dont get any errors (in IE)
in Netscape my browser stops responding
Occasionally I get this error (in IE) "Object expected" at this line
this.rsapplet.startRequest(request.id,url_context,url,this.REQUEST_MODE_COMPLETE);

this is a part of the following function
function _MSRS_startRequest(url,method,args,cb,ecb,context)
I appreciate ur time
Thanks
Avatar of farzinm

ASKER

Yes I do have Norton on my PC
>> If so, does the script blocking is set to OFF >>

what does that mean?
Hi farzinm,
  I doubt that remote scripting works on Netscape. I do not know exactly witch version it is working on Netscape but each time I've done some work with Remote scripting and Netscape was involve It had never work out. So in my mind Remote Scripting and Netscape was a combination to forget.

Second for the Norton blocking script, you have to open Norton and check the option. One of them is "Script Blocking" or something like that. This option has to be disable or turn off or else the remote scripting  wont work.

Now for your code, post your code, I would need your calling page(the one who call the remote scripting function) and your function. No need to have the _scriptLibrary files, only YOUR code. I will try to run it here and find the error.

Welcome to the wonderfull world of remote scripting! :-)
It maybe seem complex at the begining but very simple and very powerfull/helpfull on certain task. But you really have to bother with Netscape compatibility...

Post your code.

Cheers
Avatar of farzinm

ASKER

Well I am just learning so it doesnt really matter to me if this doesnt work in Netscape as long as I can work it on IE

RSClient.htm
<HTML>
<HEAD>
<TITLE>Servin' It Up with Remote Scripting</TITLE>
<BODY onload="refresh_list()">

<SCRIPT Language="JavaScript" src="../_ScriptLibrary/rs.htm">
</SCRIPT>
<H2>Address Book Sample</H2>

<FORM id=form1 name=form1>
 <INPUT type="text" size="50" id=Myname name=MyName onkeyup=refresh_list()><br>
 <SELECT id=NameList name=NameList size=10>
- One Moment Please ----------------------------------------------------------------------
</SELECT>
</FORM>
<SCRIPT LANGUAGE=javascript>
<!--
RSEnableRemoteScripting("../_ScriptLibrary")

function refresh_list()
{
 var serverURL = "server.asp"; /* Filename of our server-side script */
 var DisplayLength = 10   /* Maxinum number of records to return */
 document.form1.NameList.length = 0
 document.form1.NameList.length = DisplayLength
  var inValue = document.form1.MyName.value;
  var myVar = RSExecute(serverURL, "myFunction", inValue, DisplayLength);
  var myArray = myVar.return_value.split(":");
  for (i = 0; i < 10; i++)
  {
    var myOpt = new Option
    myOpt.value = myArray[i];
    myOpt.text  = myArray[i];
    if (i < myArray.length)
    {
      document.form1.NameList.options[i] = myOpt;
    }
  }
  document.form1.NameList.options[0].selected = true;
 }
//-->
</SCRIPT>
</BODY>
</HTML>

This is the asp file
server.asp
<%@ LANGUAGE=VBSCRIPT %>
<!--#include file="_ScriptLibrary/rs.asp"-->
<% RSDispatch %>

<SCRIPT Language=JavaScript RUNAT=SERVER>
 function Description()
 {
  this.myFunction = myFunction;
 }
 public_description = new Description();

function myFunction(strInput, numLength)
    {

   var objConn = Server.CreateObject("ADODB.Connection");
  objConn.Open("dsn=test;uid=test;pwd=test");
      var objRS = Server.CreateObject("ADODB.Recordset");
      objRS.MaxRecords = numLength;

      objRS.Open("SELECT lname, fname FROM Authors Where (lname + ', ' + fname) >= '" + strInput + "' ORDER BY lname, fname", objConn, 0, 3);

      var tmpMsg = new String;
      tmpMsg.value = "";

    while (!objRS.EOF)
      {
        tmpMsg.value = tmpMsg.value + objRS("lname") + ", " + objRS("fname") + ":";

        objRS.MoveNext();
      }
     objConn.Close();
         
      return tmpMsg.value;
    }
</SCRIPT>

Am using MYSQL as my backend. I am sorry I may sound dumb but I couldnt find the "Script Blocking" option.
I am sure by the end of this I will learn something thanks to u!
How to disable script blocking in Norton AntiVirus 2002 or 2003 ; http://service1.symantec.com/SUPPORT/nav.nsf/docid/2001082912274906

How to disable Script Blocking in Norton AntiVirus 2001 ;
http://service1.symantec.com/SUPPORT/nav.nsf/docid/2001031311101006

A bit more information;
http://service4.symantec.com/SUPPORT/nav.nsf/aab56492973adccd8825694500552355/fa999a879aac3b2f88256b450071c66e?OpenDocument

For the remote scripting thing if it's only to learn I will post you one example during the day. It's hard to know what's the problem exactly with this one...

Cheers
Avatar of farzinm

ASKER

Can you post me a working example ?
Thanks
Hi farzinm,
   Sorry bout the delay, I had a work rush. I'll do you simple example with some hardcoded value (simulating values from the db). I'll post it. I'll have it done by tomorow as am still stuck here.

Did you finally found the remote scripting blocking option from Norton?

And seem's that you still have the problem but the scripting must be off.

I'll get back to you. Sorry for this delay
Cheers.
Avatar of farzinm

ASKER

Yeah u guessed it right..I think I dont have the right to do it :( for its a corporate edition.
Also from what I read I think it is risky too to turn scripting on right?
Hi farzinm,
   Here is a working example I just did. This example is working very good so if it is not working for you, than the problem is else where than in the code. Maybe other settings.



You will have to create a Access database with one table;
database name = car.mdb
Table name = tblCar
Field = Manufacturer (type=text)
Fiedl = Model (type=text)
index = idxMan on field manufacturer in asc order.

Once create you could put those value in it

Manufacturer      Model
Dodge           Dakota
Dodge              Durango
Dodge              Stratus
Dodge              Caravan
Ford              Mustang
Ford              Festiva
Ford              Taurus
Ford              Blazer
Honda              Accord
Honda              Civic
Honda              Prelude
Honda              Tracker

once you have this done, I suppose here that you have the _ScriptLibrary folder in the wwwroot folder. And of course in this folder you must have the rs.asp,rsproxy.class and rs.htm.

so here is the 2 page that you could copy past. You must save those page in wwwroot folder.


===========================================================
this page is call remexample.asp
===========================================================
<% @ Language=VBScript %>
<html>
<title>Remote scripting example</title>
<head>
<!-- Next two lines are to initiate and enable remote scripting -->
<script language="JavaScript" src="_scriptlibrary/rs.htm"></script>
<script language="JavaScript">RSEnableRemoteScripting("_scriptlibrary");</script>
</head>


<table border="0" cellpadding="1" align="center">
   <tr><td width="50%">
      <PRE><CENTER><B><FONT SIZE="" COLOR="navy">Select a Manufacturer</FONT></B></CENTER></PRE>
<table border="0" cellpadding="1" align="center">
      <tr>
        <td valign="top"><B>Manufacturer</B></td>
        <td align="left" valign="top">
            <select name="manufac" ID="manufac" size=1 onChange="RefreshList()">
            <option selected>&nbsp;-Manufacturer-&nbsp;</option>
                     <option value="Ford">Ford</option>
                     <option value="Dodge">Dodge</option>                  
                     <option value="Honda">Honda</option>
        </select>*
      </td>
      </TR>
      <tr>
            <td valign="top"><B>Make = </B></td>
              <td>
            <select name="make" ID="make" size=1>
            <option selected>&nbsp;- Make -&nbsp;</option>
        </select>
       </td>

      </tr>
</table>
</TR>
</table>


<script language=VBScript>
'The name of the page containing the remote scripting functions
strDBPage = "rsfilter.asp"

'This sub is call when you select a manufacturer. It call the remote script function
'and return the values inside the make list box
sub RefreshList
    'Set an object instance of manufactuer list box
      set objManufac = document.all("manufac")
      'set an object instance of make list box
      set objMake    = document.all("make")

    'clear the make list box
      while objMake.length > 0
        objMake.remove (0)
    wend
      
      'Call the remote-script function
      'RsExecute pass those param; Function to be execute-> first value
    set objRS = RSExecute(strDBPage ,"GetMake", objManufac.value)
    sRS = objRS.return_value
    aRows = Split(sRS, Chr(13))

    if sRS = "" then
         'no result returned
      else
        for i = 0 to UBound(aRows) - 1
          aFields = Split(aRows(i), ";")
          set objOption = document.createElement ("OPTION")
          objOption.Value = aFields(0)
          objOption.Text = aFields(0)
          objMake.add objOption
      next
    end if
end sub

</script>
</html>

==========================================================



==========================================================
This page is the one that contains the remote functions.
name this page = rsfilter.asp
==========================================================
<%@ LANGUAGE=VBSCRIPT %>
<%
strconn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("car.mdb") & ";"
%>
<% RSDispatch %>
<!--#INCLUDE FILE="_ScriptLibrary/rs.asp"-->
<SCRIPT RUNAT=SERVER Language=javascript>
    function Description()
    {
          this.GetMake = Function('IDManufac', 'return GetMake(IDManufac)' );
    }
    public_description = new Description();
</script>

<SCRIPT RUNAT=SERVER Language=VBScript>
   
   function GetMake(IDManufac)
      set objRS = createobject("ADODB.Recordset")
        Sql = "SELECT Model FROM tblCar WHERE Manufacturer = '" & IDManufac & "'"
        objRS.Open Sql,strconn
        if not objRS.EOF then
        GetMake = objRS.GetString(, , ";")
      end if
        objRS.Close
      set objRS.ActiveConnection = nothing
      set objRS = nothing
   end function
   
</SCRIPT>
==========================================================


So here you go. Of course you could do (once you get the idea) a lot of combination and diference. For example you could have has many list box depending as you want.

You could do a sort of intelligent search where lets say in a text box, on the third digit entered (trigger by the keyup event) you call a remote function to auto populate a list with matching value. Example you want to have a search text box, when user enter lets says "Dod" then you autopopulate all record that match "Dod" in your db and so on. A sort of auto-filtering.

Anyway, when you'll get to know how it works you'll find this very very powerfull and helpfull. But Once again , beware of compatibility issue.


Let me know if you have some questions.

Cheers
Hi there,
   Just another advise, since it's hard with remote scripting to know what error exactly the page have when it's not working, because it wont output to error on the html page like normally, you simply have to turn on the script debugging option in your IIS administration panel. With this feature on, you will get to know exactly the problem inside the remote script page.


Cheers
ASKER CERTIFIED SOLUTION
Avatar of DaDMan
DaDMan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of farzinm

ASKER

Hi DaDMan
Thanks for all your help. Havent tried your code but will do so on Monday and get back to you.
Ok, let me know how it works.

Cheers
Avatar of farzinm

ASKER

You are a genius. It works! thanks a lot
Avatar of farzinm

ASKER

This is a bit strange..the above code that I posted seems to work now..earlier I had the files in a folder and now I have them in the root directory of my project file..strange. I think I might have missed out something earlier.
Well maybe only the problem was your dsn less string path...

Well am happy that everything works out good for you now and you'll find remote scripting very very interesting.


Cheers