Implement complex AJAX requests with Dojo

Source: Internet
Author: User
Keywords Ajax dojo

As a powerful front-end framework, Dojo can make it easy for developers to meet these challenges. This article will use Dojo as a tool to describe in detail how to deal with the Ajax requests of different http://www.aliyun.com/zixun/aggregation/12445.html "> Business requirements.

Before you read this article, you need the following knowledge:

Ajax Technology: Ajax's English full name is: Asynchronous JavaScript and XML, from the name can be seen Ajax is an asynchronous way of interacting with the server business. Typically, JavaScript code that runs in a browser is single-threaded. Ajax asynchronous interaction means that the foreground JavaScript program will not block in waiting for the server to respond to the process. This allows the foreground program to remain active and responsive. Please refer to Ajax Technical Resource Center for AJAX content. Dojo Framework: Dojo is a powerful front-end framework that provides convenient Ajax methods, rich widgets, data structures, accessibility functions, effects, and layout help. For more information on dojo, refer to the Dojo technical topics. XMLHttpRequest object: This is a JavaScript object that is used to send a request and receive server response to the server. For more information, please refer to the relevant resources. Asynchronous Programming Mode: This pattern becomes more and more important in web programming and is typically used to perform operations that may take longer. Instead of waiting for a long operation to complete or cause blocking, asynchronous Programming mode returns an object that represents the operation immediately. A callback function registered with the object is invoked after the operation succeeds or fails. Refer to the relevant resources for the application of asynchronous programming patterns in Web programming. Concurrent and Serial AJAX requests: As the name implies, concurrent AJAX requests mean that the client sends multiple AJAX requests to the server at the same time; a serial Ajax request means that the client sends the next AJAX request after an AJAX request returns.

Dojo's application will run through this article, and the main reasons for choosing Dojo are the following two points:

Dojo provides objects specifically for asynchronous programming patterns: Dojo. Deferred. and provides many mechanisms and methods to further manipulate Deferred objects. These mechanisms and methods can facilitate the management of multiple dojo. Deferred object. Dojo encapsulates static functions (DOJO.XHR functions) that enable developers to easily trigger Ajax requests. Also, the DOJO.XHR function returns a Deferred object for asynchronous programming operations.

Based on the above content, the main contents of this article can be summarized as follows:

describes the use of DOJO.XHR functions, how to apply them to asynchronous programming patterns, and how to implement small batch Ajax request management using asynchronous programming patterns in detail with dojo. Deferredlist and Dojox.lang.async.par implementation of arbitrary-scale concurrent AJAX requests detailed introduction of DOJOX.LANG.ASYNC.SEQ to achieve any size of the serial Ajax request

Preparatory work

Server-Side Business description

Because this article mainly discusses the client implementation Ajax request. The server-side implementation is not described here, and the server is thought to have implemented all the functionality we need to describe the server-side business in the simplest way.

Let's use an example to illustrate that figure 1 shows the interaction between the server and the client.

Figure 1. Client and server-side data interaction

Figure 1. Example of client-server-side data interaction

Now there is a music management system on the server side where the music is sorted by style. The server provides two types of REST services:

/music/{categoryofmusic} Returns a summary of all songs for a category/music/{nameofsong} returns the details of a song

The client interacts with the server-side data in JSON format.

Preparing the development environment and debugging tools

Download and install the Firefox browser and install the Firebug plugin.

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.