ajax.js文件带有new AJAXRequest().postf

时间:2014-06-06 04:46:29
【文件属性】:

文件名称:ajax.js文件带有new AJAXRequest().postf

文件大小:18KB

文件格式:JS

更新时间:2014-06-06 04:46:29

new AJAXRequest().postf

ajax技术,function AJAXRequest(init) { var objPool = [], AJAX = this, _pool = AJAXRequest.__pool__ || (AJAXRequest.__pool__ = []); (function(obj) { // init xmlhttp pool, and some consts var emptyFun = function() { }; // process inti parameter obj = obj ? obj : {}; var prop = ['url', 'content', 'method', 'async', 'encode', 'timeout', 'ontimeout', 'onrequeststart', 'onrequestend', 'oncomplete', 'onexception']; var defs = ['', '', 'GET', true, _GEC('UTF-8'), 3600000, emptyFun, emptyFun, emptyFun, emptyFun, emptyFun]; var pc = prop.length; while(pc--) { AJAX[prop[pc]] = getp(obj[prop[pc]], defs[pc]); } // get the first xmlhttp, if failed then return false if(!getXHR()) { return false; } })(init); // get param or its default function getp(p, d) { return p != undefined ? p : d; } // get XMLHttpRequest from pool function getXHR() { var xhr, _vers = [window.XMLHttpRequest, "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]; var i; for(i = 0; i < _pool.length; i+=1) { if(_pool[i].readyState === 0 || _pool[i].readyState === 4) { return _pool[i]; } } for(i = 0; i < _vers.length; i+=1) { try { xhr = (_vers[i] && typeof(_vers[i]) == "function" ? new _vers[i] : new ActiveXObject(_vers[i])); break; } catch(e) { xhr = false; continue; } } if(!xhr) { throw 'Cannot init XMLHttpRequest object!'; } else { _pool[_pool.length] = xhr; return xhr; } }


网友评论