How to invoke a remote ASP without refreshing the page

Source: Internet
Author: User
Tags html page mail requires split client
A concrete example of the Refresh | Page RS Technology
In the previous post, I introduced the basic principle of RS, obviously if the RS technology used in a
The design of the website will have a lot of extraordinary effect (especially its biggest advantage, can not refresh
page, invoke the server-side code. It is because of this feature that you can write a
The traditional C/S model of the program, like the data processing of the database (I think we must be very want to know how to achieve the specific, 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, the RS technology is completely independent of the browser (of course the browser needs to at least meet the support Java
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 you can use RS technology flexibly, it is a problem to illustrate that the "asynchronous invocation" mentioned earlier
The problem. It is 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 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 needing
The data entered by the user and the data in the database are compared, 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 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 the
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,
RS technology is used in the Main.html page and you can note that no use of submit in main.html
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 will have
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>
Implementation example of &LT;TITLE&GT;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 &LT;TITLE&GT;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 ("Employee, title, city, date of employment", ",")
%>
<table border=0>
<%
For I=0 to 3
Response.Write "<tr>"
Response.Write &qu



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.