Research on using AJAX technology in Gmail

Source: Internet
Author: User
Tags http request access
Ajax
Now that Ajax is brought up, everyone will immediately recall the classic Ajax applications of Gmail and Google map. We have seen the good performance of Gmail, then its implementation you have studied it? How is it possible to implement an asynchronous invocation of XML on several different browsers? Let's take a look.

First of all, login Gmail we will first enter this page:

<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title>Gmailtitle>
<link rel="alternate" type="application/atom+xml" title="Gmail Atom Feed" href="feed/atom" />
<script src="?view=page&name=browser&ver=c0d3d44c64799453"></script>
head>
<noscript>
<font face=arial>

  </font>
JavaScript should be enabled to use Gmail in standard view. However, JavaScript appears to have been disabled, or your browser does not support JavaScript. To use standard view, change your browser options to enable JavaScript, and then try again. To use Gmail's basic HTML view (without JavaScript), click here. < p >
< /font >
</noscript>
< script >
(editor's note: the original)
</script>
</html>
This is the main frame page and browser detection page. If the browser passes instrumentation (supports JavaScript, cookies, and XML controls), write a frame code on the page

To notice is that Google played a small trick here, that is called main frame page there seems to be little things, good dongdong in that is called JS frame inside it.

We then pull this JS frame out to see:

Full of more than 1500 lines of JavaScript code!

This page has more than 240 k, almost all of which are JavaScript code. Brothers and sisters who are interested in analysis please click here to download.

In fact, most of them are commonplace JS code, but we can get a glimpse of Google's coding style: as much as possible to compress the amount of information, variable name can use a letter of no two, the function name is all two letters, the function of the passing is not, indentation is not. Although the code is not specially encrypted, it does not have much readability after processing it. Fortunately, the system's keywords can not shrink, along the name of the XML control we can find out and Ajax asynchronous loading data related to several key functions:

function vb ()
{
Vara=null;
if (R)
{
var b=fg? " Microsoft.XMLHTTP ":" Msxml2.xmlhttp ";
Try{a=new ActiveXObject (b)}
catch (c)
{
Q (c);
Alert ("You need to enable the Active Scripting feature and the ActiveX control.") ")
}
}else{
A=new XMLHttpRequest ();
if (!a) {; alert ("This browser does not support XMLHttpRequest. ")}
}
Return a
}
EMU annotation constructs an XML control and returns it to the caller

function ot (a,b) {;
try{
A.send (b)
}
catch (c)
{
Q (c);
if (c.number==-2146697208) {
Alert ("Make sure that the language settings for Internet Explorer are not blank.) ")}
}
}

EMU annotation Perform a Send data operation A:xml control B: Data to send

function Wf (a,b,c) {
Da (3);
B=ld (b);
Hf (A,B,C)
}

EMU annotation a:xml control B: URL to access C: Callback function da is a function to validate the length of a parameter
LD is a URL conversion processing function, mainly deal with the URL from the CGI parameters and page pages, etc.

function Hf (a,b,c) {
Da (3);
A.onreadystatechange=c;
A.open ("Get", b,true);
OT (A,null)
}
EMU annotations do not send data direct request Resources A:xml control B: URL to access C: callback function

function nt (a,b,c,d) {
Da (4);
A.onreadystatechange=d;
A.open ("POST", b,true);
OT (A,C)
}
EMU Note Send data and request Resources A:xml control B: URL to access c: data to send D: callback function
Basically so much, very disappointed, there is nothing new. What does it do with the returned XML after sending an HTTP request? In fact, he didn't handle it. He deals with just the most basic responsetext, while CGI generates the JS script directly to the client callback (run with eval), or generates textual information. That's why Gmail makes it easy to cross domains in several browsers.

As one of the most admired AJAX applications, XML is rarely used. The technology that is displayed on the page like this using an XML control to send and receive text messages is basically the most popular application of Ajax now, but can it also be called Ajax? I'd rather call it aj, it's called Ajah.

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.