How to manage massive Ajax requests?

Source: Internet
Author: User

With the popularity of Ajax, Ajax is now widely used in projects. It can be said that AJAX is widely used. It is difficult to manage because of a large number of Ajax requests. As a result, we often send requests in a unified manner, with a unique page or portal. So there are the following similarCode:

 Public Partial Class Ajax: system. Web. UI. Page { Protected   Void Page_load ( Object Sender, eventargs e ){ String Comm = request [" Comm "]; If (" Edituserinfo ". Equals (Comm) {edituserinfo ();} Else   If (" Adduserinfo ". Equals (Comm) {adduserinfo ();}...... Else   If (" Deleteuserinfo ". Equals (Comm) {deleteuserinfo ();} response. End ();} Public   Void Edituserinfo (){...... }......}
 
 
As the customer's needs change and the second phase of development, there may be more Ajax requests, which will create a huge if... Else if... ... Else if ..., At the same time, each request has
 
The corresponding operation will cause this class to be too large for management and understanding.
 
 
 
The factory mode is suitable for this scenario. It uses a class to encapsulate the creation logic and the instantiation/configuration options of Customer Code. The UML diagram is as follows (drawing with word is not very standard ):
 
 
 
 

Example:

1. Create an abstract class ajaxcomm.

 
Public Abstract ClassAjaxcomm {PublicHttprequest request = httpcontext. Current. request;PublicHttpresponse response = httpcontext. Current. response;Public Abstract VoidExecute ();}

Ii. factory class: Create the corresponding class based on the comm Command requested by the user and perform the corresponding operations.

PublicPartialClassAjax: system. Web. UI. Page {Protected VoidPage_load (ObjectSender, eventargs e ){StringComm = request ["Comm"];
 
// Create a Class Based on comm. Class command rules: for example, if comm is "adduser", the corresponding class name is "addusercomm" ajaxcomm = (ajaxcomm) Assembly. Load ("Web"). Createinstance ("Web. Ajax."+ Comm +"Comm");If(Ajaxcomm! =Null) {Ajaxcomm. Execute () ;}response. End ();}}

3. Implement the corresponding command class.

Public ClassEditimgcomm: ajaxcomm {Public Override VoidExecute (){...... Response. Write ("Success");}}

# Advantages and disadvantages #

+ merge creation logic and instantiation/configuration options.

+ decouples the customer code from the creation logic.

-if it can be directly instantiated, the design will be complicated.

Related Article

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.