﻿// IC资料网Ajax框架 //
function SanKeLaAjax() {
    this.XmlHttp = this.GetHttpObject();
}
SanKeLaAjax.prototype.GetHttpObject = function() {
    var xmlhttp;
    try {
        xmlhttp = new XMLHttpRequest();
    } catch (e) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlhttp;
}
SanKeLaAjax.prototype.DoCallBack = function(URL, PostValue) {
    if (this.XmlHttp) {
        if (this.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0) {
            var oThis = this;
            this.XmlHttp.open('POST', URL);
            this.XmlHttp.onreadystatechange = function() { oThis.ReadyStateChange(); };
            this.XmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            this.XmlHttp.send(PostValue);
        }
    }
}
SanKeLaAjax.prototype.AbortCallBack = function() {
    if (this.XmlHttp)
        this.XmlHttp.abort();
}
SanKeLaAjax.prototype.OnLoading = function() {
    //Loading
}
SanKeLaAjax.prototype.OnLoaded = function() {
    //Loaded
}
SanKeLaAjax.prototype.OnInteractive = function() {
    //Interactive
}
SanKeLaAjax.prototype.OnComplete = function(responseText, responseXml) {
    //Complete	
    return responseText;
}
SanKeLaAjax.prototype.OnAbort = function() {
    //Abort
}
SanKeLaAjax.prototype.OnError = function(status, statusText) {
    //Error
}
SanKeLaAjax.prototype.ReadyStateChange = function() {
    if (this.XmlHttp.readyState == 1) {
        this.OnLoading();
    }
    else if (this.XmlHttp.readyState == 2) {
        this.OnLoaded();
    }
    else if (this.XmlHttp.readyState == 3) {
        this.OnInteractive();
    }
    else if (this.XmlHttp.readyState == 4) {
        if (this.XmlHttp.status == 0)
            this.OnAbort();
        else if (this.XmlHttp.status == 200 && this.XmlHttp.statusText == "OK")
            this.OnComplete(this.XmlHttp.responseText, this.XmlHttp.responseXML);
        else
            this.OnError(this.XmlHttp.status, this.XmlHttp.statusText, this.XmlHttp.responseText);
    }
}
