Lightweight Ajax solution -- dynajax: Call the C # class method directly on the client

Source: Internet
Author: User
Preface:
MS Ajax I used in a previous project, it feels too heavy, slow, and out of problems, it is difficult to control. So I always wanted to use a controllable alternative framework.
The client JS framework is definitely the first to push jquery, with elegant and concise code, perfect support for performance and logical separation, making you feel at ease.
I have searched for some server-side frameworks. Most of the domestic code is still scattered or in the bud, and most implementations JSONThe C # class of is no longer described below, and there is no integration suggestions for security.
Today, I have discovered Dynajax, Open-source, fully-controllable Ajax Server framework. The author of the original project is a French (Mr Beno tutorial t Beguin). The author of the current translation is as follows.

Overview

Dynajax is a javascript/ajax/asp. net/C # combined with the Ajax framework, it can help us easily directly use JavaScript to dynamically call the C # method on the server side (just like DWR in the Java World ). Object serialization is based on JSON and supports mixed object conversion.
Download the latest official version (v1.04)

Dynajax v1.04

What is dynajax?

Dynajax is C #. net/asp. net is a server-side Ajax framework with prototype as the client (Translator's note: dynajax only has the prototype version, and later I will release the modified jquery version of dynajax ), it supports direct access to the server C # method from the client through JavaScript.

Who did dynajax prepare?

The following C #/ASP. NET developers: If you want to add an effective and convenient ajax to your website or professional-level project development (I use it to develop professional-level projects of my company ).

What can dynajax do? How can this problem be solved?

Suppose you are developing a professional website program. You need to save some text data-type user information to the database without sending HTML forms or refreshing new pages. Obviously, you need to use Ajax.
Are you planning to use the original XMLHttpRequest (Ajax) request data and check the returned data to send the data and confirm that the data is properly saved? This original method is cumbersome.

By using dynajax, you can easily save the text data at the cost of writing simple JavaScript (assuming there is a class "myclass", there is a public method called "savetext ", the method returns "OK" of the string type, which can be called as follows ):

 var response = MyClass.saveText(myText);
if (response == "ok") {
--- code here ---
}

It's easy to use, isn't it?
BrowseExample pageView more examples and source code.

Is dynajax synchronous or asynchronous?

Depending on your usage: If you want to call it synchronously, use this syntax format:

var response = MyClass.myMethod(myArgs);
if (response >= 2) {
--- code here ---
}

If you want to call it asynchronously, you can use the following syntax:

MyClass.myMethod(myArgs, function(response) {
if (response >= 2) {
--- code here ---
}
});

Dynajax adopts this Asynchronous Method by default.
What types of data supported by dynajax can be received by client JavaScript?

Almost all data types can be returned from the server to the client. In fact, the data is converted to JSON format (JSON is a special format for exchanging data with other languages such as C #. NET and Java, which is somewhat similar to the XML function .)
This format supports the following data types:

  • StringsString
  • Numbers(INT, decimal...) Number
  • BooleansBoolean
  • ArraysArray
  • HashTablesHash table
  • Complex objectsComposite object (composed of member variables, arrays, HashTables, arrays, and other composite objects)
  • "Null" Value

As you can see, almost all (data types) are possible: You can do it. For example, if you want to develop an eBay-type website and search for a page, visit a method that returns the [instance] list of products, and display the list-you only need to repeatedly access the returned list of JSON format properties (list) through JavaScript, then access each product [instance], and then access the [instance] attribute. This is just like what you did in C #, cool!

If you want to learn more about the JSON format, visitJSON description site(English ).
What is security?

Dynajax provides a security authentication mechanism for all methods that can be remotely accessed.
In fact, each method must be defined in the XML format configuration file. You can set whether the method needs to be-or not-access verification ..
Therefore, even hackers cannot access the methods to be verified without passing the verification.

Is it troublesome to install/set dynajax to my web application?

No problem. dynajax is based on eight files:

  • Dynajaxhandler. aspx and dynajaxhandler. CS-Ajax processors receive and dispatch all dynajax calls
  • Dynajaxscript. aspx and dynajaxscript. CS-dynamically generate client JavaScript, which is an important part of dynajax (although this file extension is aspx, it is called as JS)
  • Prototype. js-prototype framework
  • Newtonsoft. JSON. dll-A. Net JSON assembly
  • Log4net. dll-logstore
  • Dynajaxconfig. XML-dynajax configuration document (in XML format)

These eight files must be directly copied to the Web application directory. Only dynajaxconfig. XML can be configured and modified as needed. Do not modify other files unless necessary.
It's quite easy, right?
You can refer to the first dynajax tutorial.Dynajax tutorial 01Install/configure dynajax step by step.

How can I define methods and classes in the XML configuration file?

You can go to Wikipedia: configuration has a detailed explanation)

Who will provide development support for this framework?

Mr Beno consulting t Beguin and my companyOdesysPlease feel free to contact usAdmin@dynajax.orgReport the suggestions of the bugs and new features.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.