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. To remove XML Ajax, you can use the responsetext object attribute to flexibly manipulate the format of returned data. You can customize the format, for example, I usually like to use the C language to define the returned string structure, including the file header and object information. the file header is divided into the State information and the file character length, I discard the definition of the character length of the file and specify that the first character in the dead responsetex string is the status code. For example, if the constant value is set to 0, it indicates that it is normal together, and if it is not 0, it indicates that it is abnormal, there are even errors. If there is a non-0 value, the program automatically takes the second to 257 bits (Length: 256) string to form the status information, the string starting from 258 bits to the end is the normal result 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 organizes the returned code into a JS script, run the command directly after returning the result through the browser, such as eval (XMLHTTP. responsetext) in this 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.

 

SendRPCDone (frameElement, "ajax", new Array ("ajax", "ajax amsterdam", "ajax fc", "ajax ontario", "ajax grips ", "ajax football club", "ajax public library", "ajax football", "ajax soccer", "ajax pickering transit"), new Array ("3,840,000 results ", "502,000 results", "710,000 results", "275,000 results", "8,860 results", "573,000 results", "40,500 results", "454,000 results", "437,000 results ", "10,700 results"), new Array (""));

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.