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)