Thinking in AJAX (one)--ajax

Source: Internet
Author: User
Tags definition eval

It is well known that asynchronous interactions, JavaScript scripts, and XML encapsulation data are the three major features of Ajax. In fact, in practical applications, do not need to set the death of these three big law, in my opinion, ajax-x, that is, to remove the use of XML encapsulation data, but also a good design ideas, if applied properly, more light pace and clever ideas.

The general reading of data from AJAX-returned XML structures uses the XMLHTTP Responsexml object attribute, and XMLHTTP also provides another attribute, the ResponseText, which, through this property, XMLHTTP can accept string information from the text structure of the server. The AJAX that removes XML can use responsetext This object attribute, very nimble manipulate return data format, can customize the format, for example I usually like in C language that kind of file flow way to define the return string structure, has the file header and the concrete file information entity, File header is divided into state information and file character length, I discard the definition of the length of the file character, the rule of death accept the Responsetex string in the first bit of the status code, such as set a constant value of 0 to represent normal, not 0 of the number indicates abnormal, or even errors. If there is a non 0 value, the program automatically takes the second digit string consisting of 257 bits (length 256) as state information, and the string from 258 bits to the end is the normal result information returned by the server.

SUBSTRING (0,1) take the status code

SUBSTRING (1,256) fetch the server error message (Error message is not enough 256 bits to be filled with space, take the data after the trim processing)

SUBSTRING (256, end) fetch the data information returned by the server

Three times substring completes a simple but complete interactive work. is much faster than XML parsing components.

Using ResponseText to process data faster and simpler is one reason, and the other is greater maneuverability and flexibility, opening Google suggest, typing characters in the search box to give you a spelling hint, and suggest applying AJAX technology, However, when it returns data from the server, it does not use XML encapsulation or custom ResponseText format, but directly organizes the return code into a JS script, and executes directly after returning via the browser, such as eval (Xmlhttp.responsetext) This way to perform, http://www.google.com/complete/search?hl=en&js=true&qu=ajax through this link you can see suggest using AJAX to get the return data, This page is the data that the system returns dynamically after entering "AJAX" in the Google Suggest search box.

Sendrpcdone (FrameElement, "Ajax", New Array ("Ajax", "Ajax Amsterdam", "Ajax FC", "Ajax Ontario", "Ajax Grips", "Ajax FOOTB All 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 (" ")); The browser section gets this code directly after the eval can be, as for sendrpcdone this function, which of course have to implement the definition and loaded into the page. XMLHTTP's name begins with XML, allowing many people to imprison ideas and ideas, completely discarding x, and you can also make pure Ajax examples.

Of course, for large systems, in order to keep the data interface consistent and tidy, or with XML to pass more rigorous and unified point, I heard that Microsoft has launched a rewrite XML parse components of the call, Estimating whether the next version of XMLHTTP or Domparser or msxml2.domdocument will greatly increase efficiency and reduce resource consumption.

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.