Remote Scripting Advanced Tutorials---Check for errors

Source: Internet
Author: User
Check for errors
When you invoke a method in a remote scripting server script, you may encounter several errors, including syntax errors and run-time errors, and errors when you invoke the remote scripting method. The remote scripting invocation mechanism gives you a way to learn about the error messages that occur during the call.
An error handler is slightly different depending on whether you are synchronizing or calling asynchronously. If you cause an error while making a synchronous call, the remote scripting mechanism displays an error message in the browser. The error text comes from the message property of the calling object. For more information, see "Remote Scripting Call Troubleshooting" below.
However, if you produce an asynchronous call that causes an error, you can catch the error by specifying an error callback function that has a large degree of similarity to the normal callback function.
To catch errors that occur in an asynchronous call
You can specify the name of the error callback function in your own asynchronous remote scripting call. Because you must pass the function pointer of the callback function, you must use JavaScript for asynchronous method calls. If you have created an object reference to a server page, you can use the first syntax example. Otherwise, you can use the second syntax example.
CallObject = Aspobject.methodname (P1, p2[,...],
Callbackfunction, errorcallbackfunction, context)
CallObject = Rsexecute (URL, methodname, p1, p2[,...],
Callbackfunction, errorcallbackfunction, context)
For more information about generating asynchronous calls to server methods, see calling the Remote scripting method asynchronously.
Regardless of whether you are synchronizing or calling asynchronously, you can get information about the error condition by testing the properties of the calling object. If the user specifies an error callback function, the calling object is passed as a parameter, just as the normal callback function parameter passes. In particular, the following properties provide an error message:
Status contains-1 if the remote call fails.
Data contains rough information about the XML format returned by the server. This is the best source of information for debugging because it contains the full text of the error message and other messages generated by the server.
The message contains information about the error messages (if any) generated by the remote Scripting Agent process.
The error messages in the message are not necessarily the same as in the Data property. For example, if an ASP page contains a syntax error, a detailed message about the error will appear in the Data property, but the message property will contain only such a message-it indicates that the user cannot invoke the method on the ASP page.
The following script demonstrates an error callback function in the client script. The first script produces a remote scripting call and indicates the error callback function. The second script is the error callback function itself. The error callback function does not explicitly test the Call Object Status property value because the function is invoked only when the call fails.

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.