62,052
社区成员
发帖
与我相关
我的任务
分享
timeout: function() {
this.duration = new Date().getTime() - this.__start;
var r = this.onTimeout(this.duration, this); if(typeof r == "undefined" || r != false) {
this.abort();
} else {
this.timeoutTimer = setTimeout(this.timeout.bind(this), AjaxPro.timeoutPeriod);
}
},
Object.extend(Function.prototype, {
getArguments: function() {
var args = [];
for(var i=0; i<this.arguments.length; i++) {
args.push(this.arguments[i]);
}
return args;
}
}, false);
var MS = {"Browser":{}};
Object.extend(MS.Browser, {
isIE: navigator.userAgent.indexOf('MSIE') != -1,
isFirefox: navigator.userAgent.indexOf('Firefox') != -1,
isOpera: window.opera != null
}, false);
var AjaxPro = {};
AjaxPro.IFrameXmlHttp = function() {};
AjaxPro.IFrameXmlHttp.prototype = {
onreadystatechange: null, headers: [], method: "POST", url: null, async: true, iframe: null,
status: 0, readyState: 0, responseText: null,
abort: function() {
},
readystatechanged: function() {
var doc = this.iframe.contentDocument || this.iframe.document;
if(doc != null && doc.readyState == "complete" && doc.body != null && doc.body.res != null) {
this.status = 200;
this.statusText = "OK";
this.readyState = 4;
this.responseText = doc.body.res;
this.onreadystatechange();
return;
}
setTimeout(this.readystatechanged.bind(this), 10);
},
open: function(method, url, async) {
if(async == false) {
alert("Synchronous call using IFrameXMLHttp is not supported.");
return;
}
if(this.iframe == null) {
var iframeID = "hans";
if (document.createElement && document.documentElement &&
(window.opera || navigator.userAgent.indexOf('MSIE 5.0') == -1))
{
var ifr = document.createElement('iframe');
ifr.setAttribute('id', iframeID);
ifr.style.visibility = 'hidden';
ifr.style.position = 'absolute';
ifr.style.width = ifr.style.height = ifr.borderWidth = '0px';
this.iframe = document.getElementsByTagName('body')[0].appendChild(ifr);
}
else if (document.body && document.body.insertAdjacentHTML)
{
document.body.insertAdjacentHTML('beforeEnd', '<iframe name="' + iframeID + '" id="' + iframeID + '" style="border:1px solid black;display:none"></iframe>');
}
if (window.frames && window.frames[iframeID]) {
this.iframe = window.frames[iframeID];
}
this.iframe.name = iframeID;
this.iframe.document.open();
this.iframe.document.write("<"+"html><"+"body></"+"body></"+"html>");
this.iframe.document.close();
}
this.method = method;
this.url = url;
this.async = async;
},
setRequestHeader: function(name, value) {
for(var i=0; i<this.headers.length; i++) {
if(this.headers[i].name == name) {
this.headers[i].value = value;
return;
}
}
this.headers.push({"name":name,"value":value});
},
getResponseHeader: function(name, value) {
return null;
},
addInput: function(doc, form, name, value) {
var ele;
var tag = "input";
if(value.indexOf("\n") >= 0) {
tag = "textarea";
}
if(doc.all) {
ele = doc.createElement("<" + tag + " name=\"" + name + "\" />");
}else{
ele = doc.createElement(tag);
ele.setAttribute("name", name);
}
ele.setAttribute("value", value);
form.appendChild(ele);
ele = null;
},
send: function(data) {
if(this.iframe == null) {
return;
}
var doc = this.iframe.contentDocument || this.iframe.document;
var form = doc.createElement("form");
doc.body.appendChild(form);
form.setAttribute("action", this.url);
form.setAttribute("method", this.method);
form.setAttribute("enctype", "application/x-www-form-urlencoded");
for(var i=0; i<this.headers.length; i++) {
switch(this.headers[i].name.toLowerCase()) {
case "content-length":
case "accept-encoding":
case "content-type":
break;
default:
this.addInput(doc, form, this.headers[i].name, this.headers[i].value);
}
}
this.addInput(doc, form, "data", data);
form.submit();
setTimeout(this.readystatechanged.bind(this), 0);
}
};
var progids = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
var progid = null;
if(typeof ActiveXObject != "undefined") {
var ie7xmlhttp = false;
if(typeof XMLHttpRequest == "object") {
try{ var o = new XMLHttpRequest(); ie7xmlhttp = true; }catch(e){}
}
if(typeof XMLHttpRequest == "undefined" || !ie7xmlhttp) {
XMLHttpRequest = function() {
var xmlHttp = null;
if(!AjaxPro.noActiveX) {
if(progid != null) {
return new ActiveXObject(progid);
}
for(var i=0; i<progids.length && xmlHttp == null; i++) {
try {
xmlHttp = new ActiveXObject(progids[i]);
progid = progids[i];
}catch(e){}
}
}
if(xmlHttp == null && MS.Browser.isIE) {
return new AjaxPro.IFrameXmlHttp();
}
return xmlHttp;
};
}
}
var r = this.timeout(this.duration, this);