Document: check errors
When you use remote scripting to call a method in a server script, you may encounter many errors, including syntax errors, running time errors, and errors when you call the remote scripting method. The remote scripting call mechanism provides you with a way to learn the error information during the call process.
The error handling program is slightly different depending on whether you are performing synchronization or asynchronous calls. If an error occurs during synchronous calling, the remote scripting mechanism will display an error message in the browser. The error text is from the message attribute of the call object. For more information, see "Remote Scripting call fault diagnosis ".
However, if you generate an asynchronous call that causes an error, you can capture the error by specifying an error callback function, the call of this callback function is largely similar to that of a common callback function.
Capture Errors generated in asynchronous calls
You can specify the name of the error callback function in your 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 for the 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 asynchronous calls to server methods, see call Remote Scripting Methods asynchronously.
Whether synchronous or asynchronous, you can obtain information about error conditions by testing the properties of the call object. If an error callback function is specified, the called object is passed as a parameter, just like passing a common callback function parameter. In particular, the following attributes provide error information:
Status-1 is included if the remote call fails.
Data contains the rough information in XML format returned by the server. This is the best source of debugging information, because it contains the complete text of the error message and other messages generated by the server.
Message contains the error message generated during the remote scripting proxy process (if any ). The error message in the message does not need to be the same as the error message in the data attribute. For example, if the ASP page contains a syntax error, the detailed message about the error will appear in the data attribute, however, the message property will only contain such a message, which indicates that you cannot call methods on the ASP page.
The script below demonstrates an error callback function in the client script. The first script generates a remote scripting call and specifies the error callback function. The second script is the error callback function itself. The error callback function does not explicitly test the status attribute value of the called object, because the function is called only when the call fails.
<Script language = "javascript" for = "btnSquare" event = "onclick">
RsMath = RSGetASPObject ("rsadd. asp ");
Number1 = txt1.value;
Context = "squaring ";
Co = rsMath. square (number1, showResults, showErrors, context );
Function showErrors (co ){
// Dump rough data
Msg = "The raw data returned by the remote method call is"
Msg = msg + co. data
Alert (msg );
// Display friendly Information
Msg = "The following error occurred during"
Msg = msg + co. context
Msg = msg + "remote scripting call: \ n"
Msg = msg + co. message
Alert (msg );
}
</SCRIPT>
Remote Scripting call Fault Diagnosis
Finding the exact error source in a remote scripting call is not always easy, because remote scripting involves not only the customer but also multiple files on the server. However, some types of errors are common and easy to find. In addition, you can use the remote scripting mechanism's error capture program to obtain detailed information about errors during the call.
In some cases, you cannot use remote scripting for any processing, because it has not been correctly initialized. The following table lists typical initialization errors and their possible causes.
Symptom Error
Remote scripting does not work. The client page source only contains the <APPLET> tag. RSEnableRemoteScripting
The call is not within the document body. See make the Remote Scripting on the customer page valid.
Remote scripting does not work; all calls fail. ASP page is not called. Use http: // protocol instead of file ://).
Client error message. For example, when you try to call the remote scripting method, the message "undefined 'msrs '" is displayed. The RSEnableRemoteScripting method cannot be successfully called before a remote call is attempted.
The client error message "the object does not support this attribute or method," displays a line number that does not match the. HTM file. The proxy object (Rsproxy. class) cannot be found, or the URL passed in the RSEnableRemoteScripting method is invalid.
The client error message "ASP object creation failed ". The URL passed in the RSGetASPObject call is invalid. See reference ASP as an object.
If the error is on the ASP page that contains the remote call method, or if the error occurs during the call to a remote method, you can capture the error in an error callback function, in addition, you can obtain error information from the data and message attributes of the called object.
The following table lists typical problems that can be captured using error callback functions and the values in the message and data attributes. In most cases, the message property returns general information, while the data property contains detailed information about the error.
Note that the data attribute contains a certain number of XML tags and other information related to the call. The following table lists a string that appears in the property value.
Problematic message value data value
The URL of the ASP page in the RSExecute method is invalid. See the differences between synchronously calling the Remote Scripting method and asynchronously calling the Remote Scripting method, including the Page name that the user is trying to call. (Null)
The path from ASP file to Rs. asp is incorrect. See make Remote Scripting valid on the server page. "The called page does not support remote scripting ." "File inclusion not found ."
The syntax or running time in the ASP file is incorrect. "The called page does not support remote scripting ." Details related to the error, including the row number.
Try to call a method that does not exist. "Not a public function ." "Not a public function ."
The ASP constructor references functions not found in the ASP file. See make Remote Scripting effective on the server page. "The called page does not support remote scripting ." "FunctionName is not defined ."