Refresh | page | A specific example of the Refresh Rs technology
In the previous post, I introduced the basic principle of RS, obviously if the RS technology used in a Web site design will have a lot of extraordinary role (especially its biggest advantage, you can not refresh the page in the case of invoking the server side of the code). It is because of this characteristic that you can write a traditional C/S model like the program, the data processing of the database (I think we must be very interested to know how the specific should be achieved, the following will give a concrete example, debugging this broken program almost quickly put me to death, 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, RS technology is completely independent of the browser (of course browsers need to meet at least Java and JavaScript), you can use in IE or completely in the NC, which is a distinguishing feature of the difference and RDS technology.
Before we can use RS technology flexibly, we should illustrate one problem, that is, the problem of "asynchronous invocation" mentioned earlier. It is also because of the asynchronous invocation that you can only refresh a part of the page without refreshing the entire page.
Because of this feature, you can let the server to achieve in your browsing the page at the same time you enter the data validation check (this can be a series of very complex legality checks, such as the need to put the user input data and the data in the database to compare, etc., this is not the client's JS can be resolved), Then when the server returns the results of the check, you do the appropriate action (such as a pop-up dialog box to tell the 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 call way to special attention, where the callbackfunction is a client of a JS function it represents a but Rs execution of the service end of the call, will call this function immediately, and return the result 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:
Users in the browser entered the user's e-mail address, and then the user left the e-mail address input box into the next input process, this time is the RS to play, it is based on the user input address in the server database query this address, you can determine whether the user has existed, The results are then returned to the client and the client uses the DHTML technique to prompt the user for the previously entered information in an input box called "Showresult".
function Callbackfunc (objresult) {
Information to prompt the user
Window[objresult.context].value = Objresult.return_value;
}
and Rsexecute () should call Rsexecute (ServerURL, functionname, f_arg_1, Callbackfunc,
"Showresult");
Do not say, do not say, above wordy so much, I think we all see head big, below or let specific code to speak put:
(Please create a System DSN file called NW on your server before using the code, which uses the Northworld-Chinese ACCESS97 sample database)
The following example is done in this way, Default.htm is divided into two, in the Main.html page using RS technology, you can notice that in the main.html did not use to submit so if you hit the key directly on the page will not appear, you have to click on the mouse to "get information" Press the button to use this local page refresh technique. After you click the button, there is a small delay in the page (the Java applet establishes a connection to the server in the background) and then immediately returns to the normal mouse, where 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 you can 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>
Implementation example of <TITLE>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>
Implementation example of <TITLE>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"
>
</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)
{