Sammy's profile廖 显 Sammy.liaoPhotosBlogLists Tools Help

Blog


    30 May

    GMAIL:AJAX的应用

    以前不知道在哪里看到过关于提起Gmail 是用AJAX做的,其实还有Google map等等。不能说Gmail优秀,因为这几天我一直处于打不开Gmail的状况,有点抓狂了。所以大家一起来研究一下它怎么在几个不同的浏览器上可以一致的实现xml异步调用。

    登录gmail:

    <html>
    <head>
        
    <meta content="text/html; charset=UTF-8" http-equiv="content-type">
        
    <title>Gmail</< SPAN>title>
        
    <link rel="alternate" type="application/atom+xml" title="Gmail Atom Feed" href="feed/atom" />
        
    <script src="?view=page&name=browser&ver=c0d3d44c64799453"></< SPAN>script>
    </< SPAN>head>
    <noscript>
        
    <font face=arial>
            应启用 JavaScript,才能在标准视图中使用 Gmail。然而,JavaScript 似乎已被禁用,要么就是您的浏览器不支持 JavaScript。要使用标准视图,请更改您的浏览器选项以启用 JavaScript,然后
    <href="">重试</< SPAN>a><p>要使用 Gmail 的基本 HTML 视图(不需要 JavaScript),<href="?ui=html&zy=n">请单击此处</< SPAN>a></< SPAN>p>
        
    </< SPAN>font>
    </< SPAN>noscript>
    <script>

    </< SPAN>script>
    </< SPAN>html>

    这是主框架网页兼浏览器检测页。如果浏览器通过了检测(支持javascript、cookie和xml控件)则在页面上写一段框架代码

    要注意到的是google在这里耍了一个小花招,那个叫做main的框架页面里面看来没有多少东西,好东东都在那个叫js的框架里面呢。

    我们接着把这个js框架拉出来看看:

    整整1500多行的javascript代码!

    这个页面有240多k,几乎全都是javascript代码。有兴趣分析的兄弟姐妹们请点这里下载

    其实其中大部分都是老生常谈的js代码了,不过我们可以一窥google的编码风格:尽可能压缩信息量,变量名能用一个字母的绝不用两个,函数名一概都是两个字母的,函数内的会车是没有的,缩进也是没有的。虽然代码没有特地加密,但是如此处理一番之后也就没什么可读性了。还好系统的关键字是不能缩水的,顺着xml控件的名字我们可以揪出来跟AJAX异步加载数据相关的几个关键函数:

     

    function vb(){var a=null;if(r){var b=fG?"Microsoft.XMLHTTP":"Msxml2.XMLHTTP";try{a=new ActiveXObject(b)}catch(c){q(c);alert("您需要启用活动脚本功能和activeX 控件。")}}else{a=new XMLHttpRequest();if(!a){;alert("此浏览器不支持 XMLHttpRequest。")}}return a}
    //emu注释 构造XML控件并返回给调用者

    function ot(a,b){;try{a.send(b)}catch(c){q(c);if(c.number==-2146697208){alert("请确保 Internet Explorer 的”语言”设置部分不是空白。")}}}
    //emu注释 执行发送数据操作 a:XML控件 b:要发送的数据

    function Wf(a,b,c){Da(3);b=Ld(b);Hf(a,b,c)}
    //emu注释 a:XML控件 b:访问的url c:回调函数 Da是验证参数长度的函数 
    //
    Ld是一个url转换加工的函数,主要处理url自带的CGI参数和翻页的页数等

    function Hf(a,b,c){Da(3);a.onreadystatechange=c;a.open("GET",b,true);ot(a,null)}
    //emu注释 不发送数据直接请求资源 a:XML控件 b:访问的url c:回调函数

    function nt(a,b,c,d){Da(4);a.onreadystatechange=d;a.open("POST",b,true);ot(a,c)}
    //emu注释 发送数据并请求资源 a:XML控件 b:访问的url c:要发送的数据 d:回调函数

    基本上就这么多了,很失望吧,没有什么新鲜的东西。发送http请求之后它又怎么处理返回的xml的呢?事实上他没有处理。他所处理的仅仅是最基本responseText,而cgi则直接生成js脚本到客户端回调(用eval运行),或者生成文本信息。这就是为什么gmail可以轻松跨域几个浏览器了。

    作为最受推崇的一个AJAX应用,却几乎没有用到xml。像这样用xml控件来收发文本信息后在页面上展现的技术,基本上就是现在AJAX最流行的应用方式了,不过这样也能叫AJAX吗?我宁可就叫它AJ,最多叫AJAH。

    今天先到这,我再看看能不能打开Gmail。

    21 May

    The truth about running your own show

    Today, I read a article of Luke Johnson. And the advice about the running your own business is very good I think. And share for my friends who is fighting for on this road.

    There are a lot of misconceptions about those who build companies. The real lives of self-starters are quite different from the impression created in movies, novels or the news media. These fictions discourage some would-be entrepreneurs from giving it a go, and even influence policymakers. So let's debunk some of the most common falsehoods.

    Entrepreneurs are motivated by money. In reality they create firms by accident, or because they want to prove themselves, or because they are bored, or have a passion - rather than because they want to get rich. Studies have shown that the short phrase that best sums up the drive of those who create new enterprises is "I'll show them". Money is a way of keeping score and providing capital for the next project - not the prime objective.

    The idea is what matters.

    In fact, execution is everything. We all have brilliant concepts that never come to fruition because they are impractical, or because we are too lazy or distracted. Making it happen is what counts, and this is the difficult bit - which is why so many seemingly clever schemes fail.

     

    Entrepreneurs are born not made. Most successful business owners do not start out very young. They gain experience working for others, and learn how to run an enterprise before venturing out on their own. Just as no one is genetically programmed to be a doctor or an architect, so entrepreneurs tend to find their calling by nurture rather than nature.

    Start-ups are one-man bands.

    Most companies that do well are developed by teams. A prime mover often gets most of the attention - and possibly the rewards - but it is the winning combination of skills formed by a partnership of players that is the most likely formula for success.

    Entrepreneurs are inventive geniuses.

    Very few inventors make it big in business. Rather, those who tend to strike gold are commercially-minded individuals who replicate an original

    product and make it cheaper, market it better or watch the costs properly.

    Entrepreneurs are mostly academic rejects with no qualifications.

    Today more and more business owners have university degrees or doctorates. Being an entrepreneur is now a respectable career choice, so more of the educated middle-class have taken the plunge.

    Most new businesses fail. Actually the survival rates for companies have been rising in recent years. Only a small proportion of operating enterprises go bust each year - as opposed to inactive limited companies being wound up or struck off, which distorts the statistics. And companies usually fail because of management shortcomings, rather than external forces.

    Entrepreneurs are loners.

    It takes people skills to build a company, and most entrepreneurs are extroverts who enjoy the company of others. They choose to work for themselves because they enjoy the independence, not because they want to hide away from colleagues.

    Entrepreneurs have chaotic personal lives.

    The popular image of an entrepreneur is of someone who has sacrificed everything to make a fortune - including his marriage and family. Elsewhere they are portrayed as playboys with no domestic ties. The truth is that most have a settled home life and stable relationships. The support of a steady partner is needed to help the entrepreneur through the tough times.

    Entrepreneurs are gamblers. Yes, they take financial risks, but most are good at judging the downside, and are more cautious in their ventures than it might appear to the uninformed. The vast majority of bankrupts are not entrepreneurs who failed: they are ordinary workers who borrowed too much.

    Entrepreneurs are workaholics.

    While a founder needs to be committed, most work no more hours than ambitious corporate managers. And at least the self-employed can choose their own work patterns. Moreover, surveys show the most stressful aspects of life for staff in big companies are office politics and commuting, things entrepreneurs can largely avoid.

    Entrepreneurship is neither as difficult nor as miserable as many people think. Bear this in mind next time you entertain the idea of running your own show.

     

    I fear to be eaten by vanity

       

    Yesterday I was drunk again.
     
    With my friends... ...
     
    13 May

    Indoor rock-climbing

    "Feel the intensity. Feel the burn. Don't look down. "
     
    Today, I try to join the indoor rock-climbing with my friends and share the funny. That is long time for planning to, but I awalys have no time. At the beginning, I am successful for catching the top. But for the oblique wall, I fall. I try many times still I feel a bit of ache of my arm. I think I need more practise in next time. And then we share some interesting plan in our life and we promise to go to the another high mountian each other to see the stars and milk way(maybe we have opportunity to see it) at night. (The time maybe is the end of July or early) That's nice, I look forward to the arrival of this day.
     
    PS: Today, I found the dogs (Golden Retriever) of the rock-climbing club boss is very beautiful, and irritated me to wanna have same one. That is very cool but maybe I still love the Siberian Husky more!
     
    有史以来最棒攀岩者Sharma将亮相北京
    03 May

    Travel in the Mountain

    Come back! Yesterday, I followed my travel with my friends, that was my part of life. ' You can live 100 years but if you don't travel, you only have a half life'- Meskines. World... here I came. YinChanggou, that was not very high mountain, but had beautiful foso which was the very green water and very long also. We went long the plank road which built along a cliff. Sometimes we played the water and relaxed the heart, sometimes we ran along the road like the running-competition. We shared the funny and easy in this time whatever who I was and what we did just follow the heart. What was real life in my thinking? I liked take my friends and enjoy the fresh air, green tree, beautiful view and even nice joking. Whatever the blue was.
    Nice trip!