管道基础大数据平台系统开发-【前端】-新系統界面
编辑 | blame | 历史 | 原始文档
function Skip(type = true) {
    this.async = type;
}

/**
 * 获取XMLHttpRequest对象(提供客户端同http服务器通讯的协议)
 *
 */
Skip.prototype.getXmlHttpRequest = function () {
    if (window.XMLHttpRequest) // 除了IE外的其它浏览器
        return new XMLHttpRequest();
    else if (window.ActiveXObject) // IE
        return new ActiveXObject("MsXml2.XmlHttp");
};
Skip.prototype.includeJsText = function (rootObject, jsText) {
    if (rootObject != null) {
        var oScript = document.createElement("script");
        oScript.type = "text/javascript";
        oScript.text = jsText;
        rootObject.appendChild(oScript);
    }
};
Skip.prototype.includeJsSrc = function (rootObject, fileUrl) {
    if (rootObject != null) {
        var oScript = document.createElement("script");
        oScript.type = "text/javascript";
        oScript.src = fileUrl;
        rootObject.appendChild(oScript);
    }
};
/**
 * 加载js
 *
 * @param {String} url js路径
 */
Skip.prototype.addJs = function (url) {
    var oXmlHttp = this.getXmlHttpRequest();
    var Skipthis = this;
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState === 4) {  //当执行完成以后(返回了响应)所要执行的
            if (oXmlHttp.status === 200 || oXmlHttp.status === 304) { //200有读取对应的url文件,404表示不存在这个文件
                Skipthis.includeJsSrc(document.body || document.head, url);
            } else {
                console.log('XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')');
            }
        }
    };
    oXmlHttp.open('GET', url, Skipthis.async); //url为js文件时,ie会自动生成 '