日期:2014-05-16 浏览次数:20630 次
var Ajax = (function () { //XMLHttpRequest对象 var _xMLHttpRequest = null, _funData = {/*私有方法所需的全局变量*/ readyState: 1 }, _fun = {/*私有方法*/ sendArguments: function (d) { if (typeof d === "object" && d != null) { var _d = []; for (var i in d) { _d.push(encodeURIComponent(i) + "=" + encodeURIComponent(d[i])); } return _d.join('&'); } return null; }, createXMLHttpRequest: function () {/*创建XMLHttpRequest*/ if (!_xMLHttpRequest) { if (XMLHttpRequest) { _xMLHttpRequest = new XMLHttpRequest(); } else { if (ActiveXObject) { try { _xMLHttpRequest = new ActiveXObject("Msxm12.XMLHTTP"); } catch (e) { _xMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } } } return _xMLHttpRequest; } else { _fun.createXMLHttpRequest = function () { return _xMLHttpRequest; } } }, extend: function () {/*递归合并对象*/ var i = arguments.length; if (i > 0 || typeof arguments[0] !== "object") { var _o = {}, j = 1; for (; j < i; j++) { if (typeof arguments[j] === "object") { for (var _i in arguments[j]) { arguments[0][_i] = arguments[j][_i]; } } } } return arguments[0]; }, onreadystatechangeData: [/*监控执行过程函数集合*/ function () {//readyState=0 _funData.readyState = 1; $("body").append("正在创建Ajax对象<br/>"); }, function () {//readyState=1 _funData.readyState = 2; $("body").append("readyState=“" + _xMLHttpRequest.readyState + "”Ajax对象创建完成!等待open......<br/>"); }, function () {//readyState=2 _funData.readyState = 3; $("body").append("readyState=“" + _xMLHttpRequest.readyState + "”open已发送,等待请求响应<br/>"); }, function () {//readyState=3 _funData.readyState = 4; $("body").append("readyState=“" + _xMLHttpRequest.readyState + "”正在接受响应数据,等待完成<br/>"); }, function () {//readyState=4 _funData.readyState = 0; var responseText = _xMLHttpRequest.responseText; if (_xMLHttpRequest.status === 200) { $("body").append("readyState=“" + _xMLHttpRequest.readyState + "”响应完成,执行CallBack<br/>"); if (_data.success != null) { _data.success(respon