Ajax| Development Guide Ajax relies on ServerTo distribute and process requests as intermediaries . To do this, the. NET encapsulation class relies on the client's request object, and the XMLHttpRequest object is supported by most browsers, so using this object is a good solution . Because the purpose of encapsulation is to hide the implementation of XMLHttpRequest, we do not discuss his implementation details .
Encapsulation classes are implemented by adding AJAX attribute tags to. NET methods, and once tagged, Ajax creates the client's JavaScript functions (which resemble the JavaScript functions written by the client) and uses XMLHttpRequest to create ServerProxy, this proxy maps the client's function to ServerThe handler function .
Is it complicated? No, let's take a look at the following simple example, given the. NET function
' VB.net
Public Function Add (firstnumber As Integer, Secondnumber as Integer) As Integer
return Firstnumber + Secondnumber
End Sub
|
C#
public int Add (int firstnumber, int secondnumber) { return firstnumber + secondnumber; }
|
Ajax.NET immediately automatically creates a JavaScript function with two parameters, name add, and when the client invokes the JavaScript function, the request is sent from the background to the ServerEnd and return the calculation result to the client .
Initial installation
We start with how to install ". dll" to your project, and of course, if you know how to use it, this section can skip .
If you don't have Ajax.dll, you can download the latest version of Ajax first . Unzip the file into a place that can be referenced by your project, add a reference to it in a. NET project, and then start using the Ajax.dll package for development .
|
If you are having trouble installing a reference, refer to the link's description:
Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskaddingremovingreferences.asp
|
Set up
Httphandle
In order for it to work, the first step must be to install the package Httphandle in Web.config, not to explain in detail how httphandle works, we just need to understand that they can be used to process asp.net requests . For example, all requests for *.aspx can be sent through the System.Web.UI.PageHandlerFactory class to the control handle, simply to say that we put any
ajax/*.ashx
the request sent toAjax.pagehandlerfactory Request Processing handle:
The code above tells ASP.net to match anything to a particular path (
ajax/*.ashxThe request is sent to the httphandle generated by the ajax.pagehandlerfactory and is no longer the default handler factory . You don't need to create
Ajaxsubdirectory, which is a virtual directory used only for temporary use, so other httphandler can use their own directory for the. ashx extension file .
Configuration page
Now we're ready to start coding. . Open a new Web page or a page that already exists, adding the following code to the Page_Load event in its codebehind file:
' VB.net
Public Class Index Inherits System.Web.UI.Page
Private Sub Page_Load (sender as Object, e as EventArgs) Handles MyBase.Load
Ajax.Utility.RegisterTypeForAjax (GetType (Index)) '... End Sub '... End Class |
- 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)