• 对于低版本IE,ajax的设置处理


    !(function() {
        var timeout = 16000;
        //设置ajax请求的setting配置----start
        jQuery.support.cors = true;
        $.extend($.ajaxSettings, {
            cache: true,
            timeout: timeout, //毫秒
            dataType: "json",
            type: "POST",
            xhrFields: {
                withCredentials: true
            },
            crossDomain: !0
            //      contentType: "application/x-www-form-urlencoded;charset=UTF-8"
        });
        //设置ajax请求的setting配置----end

        /**
         * 判断是否是低于制定版本的ie
         */
        window.IsLetIe = function() {
            var ua = navigator.userAgent;
            return ua.indexOf("MSIE 6") > 0 || ua.indexOf("MSIE 7") > 0 || ua.indexOf("MSIE 8") > 0 || ua.indexOf("MSIE 9") > 0;
        }

        /**
         * ajax封装 默认get
         * @param {String} url 地址
         * @param {JSON} data 数据
         * @param {String} type 数据
         * @param {Function} okFn 成功回调
         * @param {Function} failFn 失败回调
         * @param {Function} errFn 错误回调
         * @param {Function} cmpFn 完成回调
         */
        window.Ajax = function(url, data, type, okFn, failFn, errFn, cmpFn) {
            type = type ? type : 'GET';
            //ie9以下 传json string 在IE6,7,8,9下 传json后端获取不到 只能在body中读取流
            var contentType = 'application/x-www-form-urlencoded;charset=UTF-8';

            if(window.IsLetIe()) {
                data = JSON.stringify(data);
                contentType = 'text/plain';
            }
            $.ajax({
                url: url,
                type: type,
                asysc: true,
                data: data,
                contentType: contentType,
                beforeSend: function(request) {},
                success: function(response) {
                    if(response.responseCode == '001') {
                        typeof okFn == 'function' && okFn(response);
                    } else {
                        typeof failFn == 'function' && failFn(response);
                    }
                },
                error: function(xhr, msg, err) {
                    //alert('xhr-->' + JSON.stringify(xhr))
                    //alert('msg-->' + msg)
                    //alert('err-->' + JSON.stringify(err))
                    if(typeof errFn == "function" && errFn) {
                        errFn(xhr);
                    } else {
                        alert('请求失败,请稍后重试');
                    }

                },
                complete: function(response) {
                    typeof cmpFn == "function" && cmpFn();
                }
            });
        }
        /**
         * post请求
         * @param {String} url 地址
         * @param {JSON} data 数据
         * @param {Function} okFn 成功回调
         * @param {Function} failFn 失败回调
         * @param {Function} errFn 错误回调
         * @param {Function} cmpFn 完成回调
         */
        window.AjaxPost = function(url, data, okFn, failFn, errFn, cmpFn) {
            Ajax(url, data, 'POST', okFn, failFn, errFn, cmpFn);
        }
        /**
         * get请求
         * @param {String} url 地址
         * @param {JSON} data 数据
         * @param {Function} okFn 成功回调
         * @param {Function} failFn 失败回调
         * @param {Function} errFn 错误回调
         * @param {Function} cmpFn 完成回调
         */
        window.AjaxGet = function(url, data, okFn, failFn, errFn, cmpFn) {
            Ajax(url, data, 'GET', okFn, failFn, errFn, cmpFn);
        }

        var _app = {
            config: {
                environment: 'prod' //当前接口环境
            },
            domain: {
                qirong: {
                    prod: baseURL + '/'
                }
            },
            source: {
                inter: {
                    getInterInfo: 'into/getInterInfo.do'
                }
            },
            api: {
                getInterInfo: function(inputData, okFn, failFn, errFn, cmpFn) {
                    AjaxPost(_app.source.inter.getInterInfo, inputData, okFn, failFn, errFn, cmpFn);
                }
            },
            init: function() {
                //加载接口
                this.load();
                window.Api = _app.api;
            },
            load: function() {
                //遍历source 获取所有类型名称 inner,ocrweb....
                for(var type in this.source) {
                    //遍历source[type]当前的类型下的接口地址 例source.inner.creatImg
                    for(var item in this.source[type]) {
                        //将当前项的地址拼根据当前接口环境拼接上主域名
                        this.source[type][item] = [this.domain[type][this.config.environment], this.source[type][item]].join('');
                    }
                }
            }
        }
        _app.init();
    })();
  • 相关阅读:
    js合并table指定列
    jquery固定表头和列头
    Response输出excel设置文本样式
    Oracle、DB2、SQLSERVER、Mysql、Access分页SQL语句
    清除webBrowser 缓存和Cookie的解决方案
    WebBrowser加载一个URL被多次调用DocumentCompleted 的问题解决方案<转>
    Windows 2003 防火墙开启后无法访问FTP解决办法
    基于支付宝微信通知的一种个人收款回调方案(转)
    P2P技术详解(三):P2P技术之STUN、TURN、ICE详解
    turn协议的工作原理
  • 原文地址:https://www.cnblogs.com/Super-scarlett/p/8657188.html
Copyright © 2020-2023  润新知