Ajax. NET User Development Guide (3)

Source: Internet
Author: User
Tags object end error handling net return client
Ajax| Development Guide
Sample.serversideadd (100,99, serversideadd_callback);

function Serversideadd_callback (response) {
if (response.error!= null) {
alert (response.error);
Return
}
alert (Response.value);
}

As you can see from the code above, we've added an extra parameter to the Serversideadd function Serversideadd_callback, which is used to handle ServerClient function for end response . This callback function accepts a response object with four key attributes:


Value

The return value performed by the server -side function (possibly a string, custom object, or dataset)

Error

If an error occurs, an error message is returned.

Request

The original XMLHttpRequest request

Context

A Context Object

We should first check if there are errors that occur and you can pass in the ServerThe End function throws an exception to implement this error property . In this example, we simply alert a value, which is the Value property; The Request property can be used to obtain additional information (see table below)




If you want to know more about XMLHttpRequest, you can view the links below: http://www.quirksmode.org/blog/archives/2005/02/xmlhttp_linkdum.html

   Processing Type

returns a complex type

Ajax can support many types other than the int value returned by the Serversideadd function above us . He can directly support integers, strings, double, Booleans, DateTime, Datasets and DataTables, and also supports simple custom types and arrays . Other types return a string by their ToString method .

Returning a dataset works like a real. NET DataSet. Gives a return dataset to the ServiceEnd functions, we can display them on the client via the following methods:


Ajax can also support custom classes, but the need for this class to be serialized . such as the following class:

[Serializable()]
public class user{
private int _userid;
private string _FirstName;
private string _lastname;

public int userid{
get {return _userid;}
}

public string firstname{
get {return _firstname;}
}

public string lastname{
get {return _lastname;}
}

Public User (int _userid, string _firstname, String _lastname) {
This._userid = _userid;
This._firstname = _FirstName;
This._lastname = _lastname;
}

Public User () {}

[Ajaxmethod ()]
public static User getuser (int userId) {
Replace this with a DB hit or something:)
return new User (UserId, "Michael", "Schwarz");
}
}

We need to call Registertypeforajax by calling ServerRegister the user agent:
    • Ajax: A new way to build Web apps
    • Discussion on the error handling mechanism of AJAX (2)
    • Discussion on the error handling mechanism of AJAX (1)
    • First experience. NET Ajax Brushless New technology
    • A brief analysis of Ajax development Technology in Rails system (4)


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.