Ajax development experience

Source: Internet
Author: User
Tags xslt

1 Ajax or ajah
* Many typical Ajax applications actually use XMLHTTP space to access the background.ProgramThe script returned by the background program is developed using eval callback or simple data returned. The advantage of such a development model is that the design is simple and lightweight. for developers familiar with DHTML, it is easier to get started, cross-browser problems are also easy to solve, and simple applications are enough. Gmail and Google suggest all use this method. But in my opinion, the application of Gmail has reached the limit, and the more complex data structure is organized by simple data and callback methods.

* A traditional method of AJAX is to use scripts (using controls) to parse XML after returning a complete XML file in the background, and then operate the DOM node of the page to dynamically generate a part of the page. The advantage of this operation is that you can make full use of the powerful expression ability of XML to transmit various data structures. The disadvantage is that the DOM operation efficiency of the page is not high, and IE has many bugs in Dom operation APIs. The reason for this is "pre-Ajax", because we have been doing this for many years before the emergence of Ajax.

* Another traditional method of AJAX is to use scripts (Controls) to parse XML and generate HTML after returning the complete XML file in the background.CodeTo the page layer. This method avoids some Dom operations on the page. When the generated content is large, some string computing optimization techniques (mainly array and regular expression applications) are used) pages can be generated in a very efficient manner. In my opinion, this is the future development trend.

My current project mainly adopts the third method, combined with the second method. I use my own small framework to simulate JSP syntax to generate HTML code, but it is difficult to cross-browser because it depends on the XML parsing API of the browser. Google's open-source project ajaxslt provides a pure js xslt solution with more powerful functions. It can be used locally on the page to parse XML to generate HTML or other forms of data, but it brings the technical threshold of XSLT.

2 Cache
If the XMLHTTP control is used, ie will configure a cache policy when initiating an HTTP request. In many cases, the updated data cannot obtain the updated data. At first, I tried to add a random number to the URL in a traditional way to force update, but ie still sent a new request.
One solution is to write expires: 0 or other headers that disable front-end cache in the background, however, when data is not updated, unnecessary server pressure, response latency, and bandwidth waste may occur.
A better solution is to force update the data after the front-end submits the data:

XMLHTTP. setRequestHeader ("If-modified-since", "0 ");

3. system error:-1072896748.
Xmldom is often used to receive data using XMLHTTP. loadxml (XMLHTTP. responsexml. XML) to determine the correctness of the returned data, but if the background sends an incorrect XML, sometimes the system error-1072896748 is returned. This is because XMLHTTP. responsexml has not been parsed and is triggered by trying to access its XML attributes.
The solution is to try/catch when using responsexml. xml or responsetext:
Try {var TMP = XMLHTTP. responsexml. xml} catch (Ex) {err = true ;}
Some people like to judge exception. Description = "system error:-1072896748 when using catch. ", If the client is not a Simplified Chinese version system, it cannot be determined. In fact, as long as there are exceptions, the exception handling process must be followed.

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.