asp.net 2.0 Ajax

Source: Internet
Author: User
Tags stack trace

In a traditional Web application, handling exceptions is relatively straightforward-even if the developer does nothing, the browser will default to display the received exception information in the browser. For AJAX applications, things are not that simple. Ajax Program "Asynchronous" nature plus its background to run the behavior, so that users and even developers are difficult to determine whether a call to the server successfully completed, the browser is naturally the AJAX program when the operation of the exception can be powerless.

In the first two sections of this chapter, thanks to the help of the ASP.net Ajax asynchronous communication layer, we have been able to easily initiate asynchronous HTTP requests from the client to the server--ideally, this will not be a problem or enough to use. However, there are many uncertainties in the running of the Web program, from the instability of the network situation to the carelessness of the developer, any problem will cause the asynchronous call to fail.

Therefore, in the implementation of the ASP.net Ajax asynchronous communication layer, the processing method of the asynchronous call-time exception is built naturally. Remember the syntax for invoking Web service proxies at the client that you described earlier?

[NameSpace]. [ClassName]. [MethodName] (param1, param2,..., callbackfunction)

After invoking the successful callback function callbackfunction, we can also provide another callback function that failed the call. In this way, the syntax for the client to invoke the Web service proxy becomes:

[NameSpace]. [ClassName]. [MethodName] (param1, param2,..., onsucceeded, onfailed)

Note the newly added onfailed callback function in the Bold section, which will be invoked by the ASP.net Ajax asynchronous communication layer when this asynchronous communication occurs unexpectedly. The onsucceeded behavior is unaffected and will still be executed after a successful call.

The onfailed callback function will accept a parameter of type Sys.Net.WebServiceError, representing the exception object. Its function signature will resemble the following:

function onFailed(error) {
    // 取得异常信息并处理。
  }

The asp.net AJAX client Sys.Net.WebServiceError type encapsulates an exception that may occur when an asynchronous server is requested, provides several read-only properties, and provides a detailed description of the exception information. The properties of the Sys.net.webserv-iceerror type are shown in table 3-1.

Table 3-1 Properties of Sys.Net.WebServiceError type

Property Describe
Exceptiontype Get specific types of server-side exceptions
Message Get detailed Exception description information
StatusCode Gets the status code of the HTTP response that caused the exception
StackTrace Get stack trace information for server-side exceptions
TimedOut Gets a Boolean value that indicates whether the exception was caused by a network connection timeout

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.