Talking about AjaxPro.dll , asp.net Foreground JS calls background method

Time:2021-2-24

1. What is Ajax

AJAX is the abbreviation of asynchronous JavaScript and XML. The inventor of the term “Ajax” is Jesse James Garrett, while Google promotes and makes Ajax technology hot. The core idea of AJAX is to use the XMLHttpRequest object to send asynchronous requests.

2. Why use it

  • Ajax lightens the burden on the server. The principle of AJAX is “get data on demand”, which can reduce the redundant requests and the burden of the server.
  • No need to refresh the page, reduce the user’s psychological and actual waiting time. Especially when reading a large amount of data, there will be no white screen like refreshing the page. Ajax uses the XMLHttpRequest object to send the request and get the server response. Without reloading the whole page, AJAX uses JavaScript to operate DOM to update the page. Therefore, in the process of reading data, what the user is facing is not the white screen, but the original page content (a “loading” prompt box can also be added to let the user know the data being read). Only after the data is received, the content of the corresponding part of the society will be updated. This update is instantaneous and almost imperceptible to users.
  • Better user experience
  • We can transfer the burden of the previous server to the client, use the idle capacity of the client to deal with, reduce the burden of the server, make full use of bandwidth resources, save space and broadband rental costs.
  • External data can be called
  • Based on standardized and widely supported technology, there is no need to download plug-ins or applets.
  • Further promote the separation of page presentation and data

3. Ajax application scenarios

Scenario 1: data validation

Scenario 2: data on demand

Scenario 3: automatically update the page

4. AJAX development framework

  • JQuery
  • Ext
  • YUI
  • Qooxdoo
  • DWR(Direct Web Remoting)

At present, the product is added to webwork, open source (APACHE). The application framework that can call Java methods directly in JavaScript code can transfer the request calls in JavaScript to Java methods and return the execution results to JavaScript.

AjaxPro

Ajax Pro is the first free library that supports accessing server. Net through JavaScript in various ways, similar to sajax. It can send JavaScript requests to. Net methods, send them back to JavaScript from the server, and even serialize custom classes. Its main features are as follows

Session and application data can be accessed in JavaScript;

Cache query results

Free use of source code

All classes support JavaScript client to return data, and you can use dataset in JavaScript

Accessing and returning data using the htmlcontrols component

The page does not need to be overloaded, using event proxy (data access layer)

Because only one calling interface method is provided, the server CPU is very small.

Magicajax

MagicAjax integrates Ajax functions into a page in the simplest way, without modification ASP.NET Control, and there is no need to write new controls, let alone JavaScript. It has the following features:

The application configuration is simple and easy to use;

Ajax function can be realized with only one Ajax shell. Just put the control that needs no brush into Ajax shell.

Ajax function and common postback can coexist in one webform. Magic Ajax processing module only deals with the callback action of the control contained in Ajax protocol.

The content of viewstate is visible to postback and callback. Therefore, both viewstate generated by callback and postback are visible;

Provide an event model similar to postback callpack

Support IE and Firefox

Anthem.NET

Compared with traditional Ajax technology, Anthem.NET It has the following advantages:

It doesn’t need any technology upgrade. People who don’t use ajax technology before can realize asynchronous interaction according to the previous programming method;

support asp.net 1.1 and asp.net two

5. Ajax Pro description

This document will use AjaxPro.Net Framework to achieve Ajax function: call the server method asynchronously on the client side. AjaxPro.Net Is an excellent. Net environment Ajax framework, the usage is very simple, you can refer to the relevant information, This document describes several key points of using Ajax pro with a simple example. This example implements a simple function. The server returns the result of adding 1 to the number entered in the page to the client (note that there must be an Ajax Pro package, that is AjaxPro.dll File, which can be downloaded from VSS).

6. An example of Ajax Pro

6.1. Add AjaxPro.dll application

2.1.1 open the project with vs. in its resource manager, right-click reference and left-click “Add Reference”, as shown in Figure 1_ 1

Figure 1-1

2.1.2 as shown in Figure 1_ 2, click Browse to find AjaxPro.dll Where the file is, double-click AjaxPro.dll , and then click OK.

Figure 1-2

2.1.3 in the reference folder of the resource manager, you can see Ajax pro, which indicates that the reference is added successfully, as shown in Figure 1_ 3.

Figure 1-3

2.2 configuration web.config

The purpose of this step is to ensure that the client’s requests (post and get) to “ajaxpro / *. Ashx” are all processed AjaxPro.AjaxHandlerFactory Intercept.

open web.config File in < configuration >< system.web >Add the following code after,

<httpHandlers>

<addverb=”POST,GET”path=”ajaxpro/*.ashx”type=”AjaxPro.AjaxHandlerFactory, AjaxPro”/>

</httpHandlers>

As shown in Figure 2_ 1.

Figure 2-1

2.3. Add server method

2.3.1 open the background code and open the_ Add the following code to the load method,

AjaxPro.Utility.RegisterTypeForAjax (typeof (the class name of the class in which it belongs));

As shown in Figure 3-1.

Figure 3-1

Its function is to output the following code to the client:

<script type=”text/javascript” src=”/ch33/ajaxpro/core.ashx”></script>

<script type=”text/javascript” src=”/ch33/ajaxpro/ch33.Verify,ch33.ashx”></script>

2.3.2 to add a number plus one, first add one before the method[ AjaxPro.AjaxMethod ]Then write the method like the C # method, as shown in Figure 3-2

Figure 3-2

Note: need to add[ Ajax.AjaxMethod ]Identification, so that it can be accessed by the client

2.4 add foreground code

Add JS script in the foreground and call the server-side method, as shown in Figure 4-1( Try.AjaxTest.Add (Num), try is the page class, that is, the namespace of the Ajax test class, here is try; Ajax test is the class name, and add is the method name)

Figure 4-1

2.5 operation procedure and inspection results

According to the above four steps, the expected effect can be achieved, as shown in Figure 5-1.

AjaxPro.dll Resource download address:http://xiazai.jb51.net/202007/yuanma/AjaxPro_jb51.rar

Here is a brief introduction to this article AjaxPro.dll , asp.net Front JS calls the background method of the article introduced to this, more related AjaxPro.dll , asp.net Front JS call background content, please search previous articles of developer or continue to browse the following related articles, I hope you can support developer more in the future!