Essence | Abstract Source: www.yesky.com
Paste-How to invoke remote ASP without refreshing the page (2000.03.30)
A concrete example of RS technology
In the previous post, I introduced the basic principle of RS, obviously if the RS technology used in a
The design of a website will have a lot of extraordinary effect (especially its biggest advantage, can be in not brush
To invoke the server-side code in case of a new page. It is because of this feature that you can write a
Traditional C/S model of the program, as the database data processing (I think we must be very interested to know
Specifically how to achieve, the following will give a concrete example, debugging this broken program almost quickly
I am tired, hehe. )
As you can see from the previous description, using RS technology requires the client and server to meet the following two
Conditions:
1. The client only needs to support Java applets
2. And the server only need to support ASP can
In other words, the RS technology is completely independent of the browser (of course browsers need to satisfy at least support JA
Va
and JavaScript), you can use it in IE, or you can completely
NC, which is a notable feature of the distinction and RDS technology.
Before we can use RS technology flexibly, we should explain one problem, which is mentioned before.
Asynchronously invokes the
The problem. It is because of the asynchronous invocation that you can only refresh a part of the page without brushing
New
The entire page.
Because of this feature, you can enable the server to achieve while you are browsing the page
Check the legality of your input data (this can, of course, be a series of very complex legality checks, such as the need to
To
The data entered by the user and the data in the database are compared and so on, this is not the client's JS can
enough to solve)
Then when the server returns the results of the check, you do the appropriate action (such as a pop-up dialog box to tell
User
Input error, etc.)
The syntax for an asynchronous call is as follows:
Rsexecute (ServerURL, functionname, Param_list)
The first parameter is the full URL path of the ASP page you want to invoke
The second argument is the name of the function you want to call
The following is the input parameter that the function needs.
If the function you want to call requires two input parameters, this is the way it is written:
Rsexecute (ServerURL, functionname, f_arg_1, f_arg_2)
There are two ways to do this when the call is made,
One is the invocation of a return result:
Objresult = Rsexecute (ServerURL, functionname, f_arg_1, f_arg_2);
The other is a way of calling that does not return results:
Rsexecute (URL, func_name, f_arg_1, F_arg_2, callbackfunction);
This type of invocation should be specially noted, where the callbackfunction is a JS function of the client
It represents a call to the server at the end of the RS execution, and the function is called immediately and the result is returned
To this
function.
A typical callbackfunction function should be such a structure:
function Callbackfunction (objresult) {
Your own process.
}
The only input parameter Objresult is the return value of the RS call.
Let's assume a situation like this:
The user enters the user's e-mail address in the browser, and the user leaves the e-mail address input
Box
Into the next input process, this time is RS to play, it is based on the user input address in
Server-side database to query this address, you can determine whether the user already exists, and then
Return the results to the client, and then use the DHTML technique on the client in an input box called "Showresult"
It prompts the user for the information previously entered.
function Callbackfunc (objresult) {
Information to prompt the user
Window[objresult.context].value = Objresult.return_value;
}
and Rsexecute () should call this
Rsexecute (ServerURL, functionname, f_arg_1, Callbackfunc, "Showresult"
);
Do not say, do not say, the above wordy so much, I think we all see the head is big, the following or
Let the specific code to speak put:
(Please create a System DSN file called NW on your server before using the code, which uses the
Northworld is a sample database with Chinese ACCESS97
The following example is carried out in this way, and the Default.htm is divided into two frames,
The RS technology is used in the Main.html page and you can note that main.html is not used in the SUBM
It
So if you hit enter directly on the page, nothing will happen, you have to click through the mouse
The "Get Info" button to use this local page refresh technique. After you click the button, the page
Yes
A small delay (the Java applet establishes a connection with the server in the background during this period)
Then immediately the page reverts to the normal mouse, and you can continue to do other things on the page.
Instead of being refreshed like normal pages, you only have to wait for data.
And info.asp everyone can see at a glance, in fact, is a very simple process of string processing.
If you are familiar with DHTML technology, you can complete these operations on the client side.
As for the empdata.asp is the server process data processing program.
Well, the benefits of which everyone can go on their own
Experience.
Pay special attention not to change too much code, otherwise it is easy to make mistakes, after all, in the use of JavaScript programming
The Default.htm file code is as follows:
<HTML>
<HEAD>
<TITLE> implementation examples for RS technology </TITLE>
</HEAD>
<frameset id=fset rows= "70%,30%"
<frame name=main src= "main.html"
<frame name=info src= "info.asp"
</FRAMESET>
</HTML>
The maim.html file code is as follows
<HTML>
<HEAD>
<TITLE> implementation examples for RS technology </TITLE>
</HEAD>
<BODY>
<script language= "JavaScript" src= "Http://YourServer/_ScriptLibrary/rs
. htm "> </script>
<script language= "JavaScript" >
Rsenableremotescripting ("Http://YourServer/_ScriptLibrary");
</script>
<form name=myform>
Please input the name you want to inquire:
<br> <input type=text name= "Emplastname" size=40>
<input Type=button name=btnexecute style= "width=150"
Value= "Get Information"
onclick= "Execasynch (emplastname.value)" >
</form>
<script language= "JavaScript" >
var ServerURL = "Http://YourServer";
var pageurl = "/batman/empdata.asp";
function RefreshPage (CO)
{
if (co.status!= 0) {
Alert ("Abnormal error \ n" +
message);
}
StrText = Co.return_value;
Top.info.location = "info.asp?info=" + Escape (StrText);
}
function Execasynch (emplastname)
{
Rsexecute (Serverurl+pageurl, "Getempinfoasarray"),
Emplastname, RefreshPage);
}
</SCRIPT>
</BODY>
</HTML>
Info.asp File Code
<HTML>
<BODY>
<%
Response.Write Request.ServerVariables ("Remote_user")
StrText = request.querystring ("info")
If StrText = "" Then Response.End
Arrdata = Split (StrText, "|")
Arrlabels = Split (&q