---
title: "百度的Ajax.js文件(转载)"
author: "mmdev"
date: "2007-10-17T21:58:00Z"
tags: []
slug: "ajax-js"
draft: false
lastmod: "2012-04-14T20:15:13Z"
id: 1486387
url: "https://mmdev.iteye.com/blog/1486387"
---

百度的Ajax.js文件(其实就在百度页面上挂着呢……)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Title:\[Ajax.js简介]  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)文件名:ajax.js  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)版本:v1.0.0-100  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)版权:(c)Baidu.com  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)作者:chenlin  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)简介:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;这个文件是对xmlhttp异步请求进行了简单的封装，  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;主要是将prototytp进行了简化，如果要使用复杂的功能可以使用prototype的ajax.js  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;外部使用时，主要调用方式为  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;varmyAjax=newAjax.Request(  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;url,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;method:'get',  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;asynchronous:true,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;onSuccess:function(xmlHttp)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;onFailure:function(xmlHttp){  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;onException:function(exception){  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;另可使用myAjax.header()和myAjax.evalResponse();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;其他的都为内部调用函数，外部尽量不要使用。Class:Ajax.Request类  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)Function.prototype.bind=function(object)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)var\_\_method=this;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)returnfunction()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\_\_method.apply(object,arguments);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)基础ajax类  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;封装了一个函数：Ajax.getTransport()返回一个xmlhttp对象  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;这个类里的函数一般不使用。  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)varAjax=...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)getTransport:function()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnTry.these(  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)function()...{returnnewActiveXObject('Msxml2.XMLHTTP')},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)function()...{returnnewActiveXObject('Microsoft.XMLHTTP')},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)function()...{returnnewXMLHttpRequest()}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif))||false;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)基础ajax.base类  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;封装了三个函数：  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;setOptions：设置进行ajax请求的参数  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;responseIsSuccess：判断异步请求返回是否成功  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;responseIsFailure：判断异步请求返回是否失败  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;这个类里的函数也没有必要在实际中使用，只有在扩展是才会使用到  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)Ajax.Base=function()...{};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)Ajax.Base.prototype=...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)setOptions:function(options)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)this.options=...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)method:'post',//异步请求方法，可以为get和post，此处为默认post  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)asynchronous:true,//设置是否为异步方式发送，  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)parameters:''//传递参数，参数都是url编码格式a=valueOfA&b=valueOfB  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)Object.extend(this.options,options||...{});//以上三个属性为异步请求的基本属性。  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)responseIsSuccess:function()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnthis.transport.status==undefined  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)||this.transport.status==0  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)||(this.transport.status&gt;=200&&this.transport.status&lt;300);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)responseIsFailure:function()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)return!this.responseIsSuccess();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*生成一个类Ajax.Request  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)Ajax.Request=newClass();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)定义了xmlhttp请求的状态。  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;0(未初始化)对象已建立，但是尚未初始化（尚未调用open方法）  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;1(初始化)对象已建立，尚未调用send方法  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;2(发送数据)send方法已调用，但是当前的状态及http头未知  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;3(数据传送中)已接收部分数据，因为响应及http头不全，这时通过responseBody和responseText获取部分数据会出现错误，  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&gt;4(完成)数据接收完毕,此时可以通过通过responseBody和responseText获取完整的回应数据  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)Ajax.Request.Events=\['Uninitialized','Loading','Loaded','Interactive','Complete'];  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*Ajax.Request对象，需要实例化对象，  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)Ajax.Request.prototype=Object.extend(newAjax.Base(),...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)initialize:function(url,options)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.transport=Ajax.getTransport();//返回xmlhttp对象  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.setOptions(options);//设置请求的参数，在初始化时写  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.request(url);//进行异步请求  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)request:function(url)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)varparameters=this.options.parameters||'';  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(parameters.length&gt;0)parameters+='&\_=';  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)try...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.url=url;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*如果是get方法的化，就将parameters里的内容添加到url里  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(this.options.method=='get'&&parameters.length&gt;0)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.url+=(this.url.match(/?/)?'&':'?')+parameters;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*调用xmlhttp的请求函数，进行请求  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.transport.open(this.options.method,this.url,  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.options.asynchronous);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*如果是异步请求，对onreadystatechange绑定函数，对于为什么要用定时器，没10ms将状态设为Loading，我也没有明白。  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if(this.options.asynchronous)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.transport.onreadystatechange=this.onStateChange.bind(this);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)setTimeout((function()...{this.respondToReadyState(1)}).bind(this),10);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.setRequestHeaders();//设置请求里的头部信息，包括编码等信息  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*对与post方式请求，也可以通过options里的postBody来设，这里就将postbody放到参数里进行传递  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)varbody=this.options.postBody?this.options.postBody:parameters;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*发送post数据  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.transport.send(this.options.method=='post'?body:null);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)}catch(e)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.dispatchException(e);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)setRequestHeaders:function()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)varrequestHeaders=\['X-Requested-With','XMLHttpRequest'];  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if(this.options.method=='post')...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)requestHeaders.push('Content-type',  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)'application/x-www-form-urlencoded');  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//\*Force"Connection:close"forMozillabrowserstoworkaround  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*abugwhereXMLHttpReqeuestsendsanincorrectContent-length  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*header.SeeMozillaBugzilla#246651.  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(this.transport.overrideMimeType)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)requestHeaders.push('Connection','close');  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(this.options.requestHeaders)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)requestHeaders.push.apply(requestHeaders,this.options.requestHeaders);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)for(vari=0;i&lt;requestHeaders.length;i+=2)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.transport.setRequestHeader(requestHeaders\[i],requestHeaders\[i+1]);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*状态改变时，执行respondToReadyState，判断当状态为1时不执行。  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)onStateChange:function()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)varreadyState=this.transport.readyState;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(readyState!=1)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.respondToReadyState(this.transport.readyState);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*返回异步请求返回文件的头部信息，name表示名字，函数返回参数值  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)header:function(name)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)try...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnthis.transport.getResponseHeader(name);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)}catch(e)...{}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*如果返回header信息里包括X-JSON/xxx，则会执行xxx的内容  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*不是很明白这里，为什么要eval  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)evalJSON:function()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)try...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returneval(this.header('X-JSON'));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)}catch(e)...{}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*很简单的函数，如果返回Content-type为text/javascript，则会调用此函数进行执行，我认为这处用途不大  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)evalResponse:function()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)try...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returneval(this.transport.responseText);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)}catch(e)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.dispatchException(e);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*根据返回的状态决定该执行的步骤  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)respondToReadyState:function(readyState)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)varevent=Ajax.Request.Events\[readyState];  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)vartransport=this.transport,json=this.evalJSON();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if(event=='Complete')...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*此处如果状态处于完成状态则会进行分析分别调用onSuccess和onFailure，所以一般onComplete不调用为好  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)try...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)(this.options\['on'+this.transport.status]  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)||this.options\['on'+(this.responseIsSuccess()?'Success':'Failure')]  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)||function()...{})(transport,json);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)}catch(e)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.dispatchException(e);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*此处对返回js进行了eval  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if((this.header('Content-type')||'').match(/^text/javascript/i))  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.evalResponse();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)try...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)(this.options\['on'+event]||function()...{})(transport,json);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)}catch(e)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)this.dispatchException(e);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*AvoidmemoryleakinMSIE:cleanuptheoncompleteeventhandler  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(event=='Complete')  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)this.transport.onreadystatechange=function()...{};  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)},  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*//*  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*错误时调用，一般外部使用onException:function(){}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)dispatchException:function(exception)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)(this.options.onException||function()...{})(this,exception);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif));