In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to install AJAX.NET configuration, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Ajax.NET installation configuration: download and install
First download and extract the AJAX file from the AJAX.NET project website, then create a new ASP.NET project in Visual Basic .NET or C# as you like, and then add a reference to the AJAX.dll file. The only additional configuration step is in the
< system.web>Add the following code to the element (located in the web.config file).
< configuration> < system.web> < httpHandlers> < !-- Register the ajax handler --> < add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" /> < /httpHandlers>......
< /system.web> < /configuration>AJAX.NET installation configuration: make server-side functions available
To make server-side functions available in JavaScript, you must do two things. First, the function to be used must be labeled Ajax.AjaxMethodAttribute. Second, during the page load event, the class containing these functions must be registered by calling Ajax.Utility.RegisterTypeForAjax. It sounds complicated, but don't worry; you only need to add two more lines to the code. Let's look at an example.
/ / C # public class Sample: System.Web.UI.Page {private void Page_Load (object sender, System.EventArgs e) {/ / register the class Ajax.Utility.RegisterTypeForAjax (typeof (Sample)) that contains the server-side function / / that we are interested in;} [Ajax.AjaxMethod ()] public string GetMessageOfTheDay () {return "Experience is the mother of wisdom" } 'VB.NET Public Class Sample Inherits System.Web.UI.Page Private Sub Page_Load (sender AsObject, e As EventArgs) Handles MyBase.Load' registers the class Ajax.Utility.RegisterTypeForAjax (GetType (Sample)) End Sub that we are interested in containing the server-side function'
< Ajax.AjaxMethod()>_ Public Function GetMessageOfTheDay () As String Return "Experience is the mother of wisdom" End Function End Class
The above example first tells Ajax.NET to look for friendly Ajax methods in the Sample class. It happens to be the same class as the actual page, but it can be any .NET class, or you can register multiple classes. Ajax.NET then browses the specified class to find all the methods labeled AjaxMethodAttribute, where the Sample class has a GetMessageOfTheDay.
AJAX.NET installation configuration: using functions and classes in JavaScript
When you're done, the only thing left to do is to use it in JavaScript. Ajax.NET automatically creates a JavaScript variable with the same name as the registered class (Sample in this case), which provides a function with the same name as AjaxMethod (GetMessageOfTheDay in this case). As shown below.
< script language="javascript">Sample.GetMessageOfTheDay (GetMessageOfTheDay_CallBack); function GetMessageOfTheDay_CallBack (response) {alert (response.value);}
< /script>In addition to the JavaScript callback function, JavaScript GetMessageOfTheDay requires the same parameters as its server-side counterpart (in this case, no parameters) in order to execute and pass the response when complete. Here, we see the asynchronous nature of AJAX at work, because the call to GetMessageOfTheDay does not prevent the execution of other JavaScript code, nor does it prevent the user from continuing to operate on the page. When the server-side processing is completed, Ajax.NET calls the specified callback function GetMessageOfTheDay_CallBack and passes it a response consisting of the server-side return value.
The mapping between server-side code and JavaScript code can be a bit confusing. Figure 1 briefly shows the server-side code and the JavaScript code, and the mapping between them.
Figure 1: mapping between server-side code and JavaScript code
Thank you for reading this article carefully. I hope the article "how to install and configure AJAX.NET" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.