Thinking in Ajax (1) -- AJAX-X

Source: Internet
Author: User

As we all know, Asynchronous interaction, JavaScript scripts, and XML Data encapsulation are three main features of Ajax. In fact, in actual application, there is no need to stick to these three rules. In my opinion, Ajax-X, that is, removing XML-encapsulated data, is also a good design idea, if the application is appropriate, the pace and clever thinking will be lighter.

Generally, the responsexml object attribute of XMLHTTP is used to read XML structure data returned by Ajax. At the same time, XMLHTTP also provides another attribute, namely, responsetext, XMLHTTP can accept string information from the server's text structure. Ajax with XML removed can use the responsetext object attribute to flexibly manipulate the format of returned data and customize the format. For example, I usually like to useC LanguageThe type of file stream that defines the returned string structure, including the object header and the object information. the file header is divided into the State information and the length of the file characters. I discard the definition of the file character length, specify the first digit of the responsetex string to be accepted as the status code. For example, if the constant value 0 is set to indicate normal, a non-zero number indicates abnormal, or even an error occurs. If there is a non-0 value,ProgramThe second-to-257-Bit String is automatically taken as the status information, and the string from the third-bit to the end is the normal result information returned by the server.
Substring (0, 1) Get status code
Substring (1,256) gets the server error message (if the error message is not enough, fill it with spaces. Trim processing is performed after the data is obtained)
Substring (256, end) obtains the data returned by the server.
Three substrings complete a simple but complete interaction. It is much faster than the XML parsing component.

Responsetext is faster than encapsulated as XML to process data. The other reason is that it is more flexible in handling. Open google suggest and enter characters in the search box to give you a spelling prompt, suggest applies Ajax technology, but it does not use XML encapsulation or customize the responsetext format when returning data from the server, but directly returnsCodeOrganized into JS scripts, direct execution after the browser returns, such as eval (XMLHTTP. responsetext) such way to execute, http://www.google.com/complete/search? Hl = en & JS = true & Qu = Ajax through this link, you can see the data returned by suggest using Ajax, this page displays the data dynamically returned by the system after "ajax" is entered in the search box of Google suggest.

After getting this code in the browser segment, you can directly eval it. As for the sendrpcdone function, you must implement the definition and load it to the page. The XMLHTTP name starts with XML, which has banned many people from thinking and creativity and completely abandoned X. You can also make pure Ajax instances.

Of course, for large systems, in order to ensure consistency and uniformity of data interfaces, we still use XML to deliver more rigorous and unified points. I heard that Microsoft has launched a call to rewrite the XML Parse component, it is estimated that the next version of XMLHTTP, domparser, or msxml2.domdocument will greatly improve efficiency and reduce resource usage.

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.