• 对于低版本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();
    })();
  • 相关阅读:
    ADB高级应用
    struts2 结合extjs实现的一个登录实例
    css3中关于伪类的使用
    漫谈并发编程(三):共享受限资源
    awk依照多个分隔符进行切割
    3星|《财经天下周刊》2017年21期:海外购几乎是亚马逊中国的最后一根救命稻草
    3星|《迷失的盛宴:中国保险产业1978-2014》:序言比正文精彩
    3星|《超级运营术》:互联网社区运营老手经验谈
    3星|《百年流水线》:流水线与工业、社会、艺术的交互史
    5星|戴蒙德《为什么有的国家富裕,有的国家贫穷》:为什么有的国家能发展出好制度
  • 原文地址:https://www.cnblogs.com/Super-scarlett/p/8657188.html
Copyright © 2020-2023  润新知