Remote Script document (reprinted from Microsoft) (V) _ Long-distance scripting

Source: Internet
Author: User
Documents: Calling Remote Scripting Method synchronization

Once you have configured a remote scripting on a customer page and on a server page, you can invoke the Server page's method from your own client script. By default, when a user invokes a server method, it is executed synchronously--your client script does not stop running until the server method completes and returns the result. Generally speaking, when you need server method results in your own client script, you need to synchronize the call to the server method.

Note You can also invoke the server method asynchronously. For more information, see Calling the Remote scripting method asynchronously.

When you call a server method, the method does not return a single value. Instead, you create a call object, which is an object that contains the return and state information of the invoked procedure. The most commonly used property is the Return_value property of the calling object, which contains a remote procedure calculation or a single value that is checked out. Other invocation object properties allow users to get more information about the status of remote procedure calls.

If you have created an object reference to a server page, you can invoke the method with the standard Object.Method syntax. For more information about creating object references, see referencing ASP pages as objects. Alternatively, you can invoke the remote scripting method when there are no object references. This is slightly more redundant than using the Object.Method syntax, but does not require the user to first create an object reference.

Synchronous Call Server method

If a user creates an object reference to a server page, the first syntax example is available for calls that use JavaScript, and for calls that use VBScript, a second syntax example is available:
Javascript:
CallObject = Aspobject.methodname (P1, p2[,...])

VBScript
Set callobject = Aspobject.methodname (P1, p2[,...])


Or

If the user does not create an object reference, call the Rsexecute function. For calls that use JavaScript, use the first syntax example, and for calls that use VBScript, use the second syntax example:
Javascript:
CallObject = Rsexecute (URL, methodname, p1, p2[,...])

VBScript
Set callobject = Rsexecute (URL, methodname, p1, p2[,...])


which

CallObject the name of the calling object that will be instantiated after the remote scripting call completes. You do not need to create the object before calling remote script, which is created for you by a remote scripting call.


Aspobject an object reference that you can optionally create earlier using the Rsgetaspobject method. For more information, see Referencing an ASP page as an object.


The URL contains the ASP page URL for the remote script you want to execute. The server page must be configured so that the Remote scripting in the Server page is valid as described in. The server page must be on the server from which the user requests the current customer page.


MethodName the name of the method on the server page you want to execute.


P1, p2, ... any parameters required by the method in the MethodName. Parameters are passed by value. Users can pass simple data types, such as numbers or text values, but cannot pass structured data, such as arrays or objects.
Note When parameters are passed from the customer to the server, they are converted to strings. Make sure that your server method converts the parameters to the appropriate data type when you use them. For detailed questions, see make the Remote scripting in the server page valid.

For example, the following button Btnadd client script onclick handler calls server method add to accumulate two numeric values. Calling the remote scripting method creates a call object named Co. The result of the remote scripting call is extracted from the Return_value property of the calling object and is displayed as a text box value named Txt3.

<script language= "javascript" for= "Btnadd" event= "onclick" >
Rsmath = Rsgetaspobject (".. /mypages/rsmath.asp ")
Number1 = Txt1.value;
Number2 = Txt2.value;
CO = Rsmath.add (NUMBER1,NUMBER2);
Txt3.value = "The sum is" + co.return_value;
</SCRIPT>


The same invocation (with Rsexecute) that is produced in the absence of an object reference may look like the following:

<script language= "javascript" for= "Btnadd" event= "onclick" >
Number1 = Txt1.value;
Number2 = Txt2.value;
CO = Rsexecute ("rsmath.asp", "Add", number1,number2);
Txt3.value = "The sum is" + co.return_value;
</SCRIPT>


For more information about how to check for errors when generating a remote scripting call, see Checking for errors.

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.