From <proficient in Javascript>
If (typeof XMLHttpRequest = 'undefined ')
XMLHttpRequest = function (){
Return new activeobject (navigator. useragent. indexof ("MSIE 5")> = 0? "Microsoft. XMLHTTP": "msxml2.xmlhttp ");
};
Function Ajax (options ){
Options = {
Type: Options. type | "Post ",
URL: Options. url | "",
Timeout: Options. Timeout || 5000,
Oncomplete: Options. oncomplete |
Function (){
},
Onerror: Options. onerror |
Function (){
},
Onsuccess: Options. onsuccess |
Function (){},
Data: option. Data | ""
};
VaR xml = new XMLHttpRequest ();
XML. Open (options. type, options. url, true );
VaR timeoutlength = options. Timeout;
VaR requestdone = false;
SetTimeout (function () {requestdone = true ;}, timeoutlength );
XML. onreadystatechange = function (){
If (XML. readystate = 4 &&! Requestdone ){
If (httpsuccess (XML )){
Options. onsuccess (httpdata (XML, options. Type ));
} Else {
Options. onerror ();
}
Options. oncomplete ();
Xml = NULL;
}
};
XML. Send ();
Function httpsuccess (r ){
Try {
Return! R. Status & location. Protocol = "file:" |
(R. Status >=200 & R. Status <300) |
R. Status = 304 |
Navigator. useragent. indexof ("safari")> = 0 &&
Typeof R. Status = "undefined ";
} Catch (e ){
Return false;
}
}
Function httpdata (R, type ){
VaR Ct = R. getResponseHeader ("Content-Type ");
VaR DATA =! Type & CT. indexof ("XML")> = 0;
Data = type = "XML" | data? R. responsexml: R. responsetext;
If (type = "script ")
Eval. Call (window, data );
Return data;
}
}