This is a the Microsoft AJAX Library quickstart exercise from Chapter 4 of Microsoft AJAX Library Essentials: JavaScript in ASP.NET AJAX 1.0 Explained.
In this exercise you learned about the XMLHttpRequest object that represents the core of any AJAX-enabled application. Asynchronous client-server communication is also a pillar of the Microsoft AJAX Library. Although this library does a great job at abstracting the low-level details from the developer, XMLHttpRequest is still used to handle the background client-server communication.
The Microsoft AJAX Library client can call server-side web service methods. Its networking layer binds together the client presentation layer and the business layer of the server side. This approach has the advantage of loosely coupling the JavaScript client to the ASP.NET server, providing an interface for them to communicate.
The networking layer in Microsoft AJAX Library works as described in the following figure:
The Microsoft AJAX Library client can use the networking layer to do one of the following:
The following figure describes the components of the Microsoft AJAX Library networking layer:
At a higher level, the client asynchronous communication (networking layer) can be divided into three parts:
The Proxies layer consists of all the proxies that access functionality from the server side:
These services are invoked in a similar way to how web services' methods are called. The methods exposed by the application services are available through their client proxies as web methods so that the same infrastructure can be used to call web service methods, page methods, and application services.
The Conversion layer is responsible for serialization and deserialization to and from the common .NET types. The default serialization is handled by the Sys.Serialization.JavaScriptSerializer class. JSON represents the default serialization format but additional serialization formats such as XML can be specified.
The Core communication layer is represented by a set of classes that make HTTP requests. The Sys.Net.WebRequestExecutor represents an "abstract" base class by convention, offering a generic interface for making web requests. The class is extended by Sys.Net.XmlHttpExecutor, which uses XMLHttpRequest to make the web requests. The logic of the web request is implemented in the Sys.Net.WebRequest class, which uses a WebRequestExecutor object (XmlHttpExecutor is used by default). All the web requests initiated by the browser are managed by the Sys.Net.WebRequestManager class that offers an additional level of control by exposing new properties, events, and methods.
See Appendix A for reference regarding these classes. We'll use them in practice in the upcoming exercise.
The purpose of this exercise is to get you a first exposure to the Microsoft AJAX Library. As you could see, the major difference between this example and the Quickstart example presented in Chapter 1 is the client-side code. The conclusions we can draw from this exercise are:
XMLHttpRequest calls manually.Implement the exercise step by step and find detailed explanations in our book, Microsoft AJAX Library Essentials: JavaScript in ASP.NET AJAX 1.0 Explained.